Edit/update from activerecords "unpermited params"
<p>I have an app that can allow proprietaire(name of user) to edit their campings(nome of post). Post have proprietaire_id. This part works.</p>

<p>I added some details on the camping (piscine, barbecue) in another table name caracteristiquetest. I made a relationship with camping_id. I can display value for piscine and barbecue. But when i try to allow proprietaire(user) to edit/update their camping, record not save and i have an error unpermited params.</p>

<p>How can i do this ?</p>

<p>Sorry for my english im french</p>

<p>camping_controller.rb</p>

<pre><code>    def update
        respond_to do |format|
          if @camping.update(camping_params)
            format.html { redirect_to @camping, notice: 'Camping was successfully updated.' }
            format.json { render :show, status: :ok, location: @camping }
          else
            format.html { render :edit }
            format.json { render json: @camping.errors, status: :unprocessable_entity }
          end
        end
      end
  def camping_params
      params.require(:camping).permit(:name, :adresse, :code_postale, :commune, :courriel, :site_internet, :tel, :description, :nomdep, :nomregion, :numdep, :slug, :ville_id, :region_id, :departement_id, :latitude, :longitude, :etoile, :user_id, :image)
      params.require(:caracteristiquetest).permit(:piscine, :barbecue)
    end 
</code></pre>

<p>camping.rb</p>

<pre><code>belongs_to :proprietaire
belongs_to :caracteristiquetest
accepts_nested_attributes_for :caracteristiquetest
</code></pre>

<p>caracteristiquetest.rb</p>

<pre><code>class Caracteristiquetest &lt; ApplicationRecord
  has_one :camping
  accepts_nested_attributes_for :camping
end
</code></pre>

<p>_form.html.erb</p>

<pre><code>&lt;%= f.select(:piscine, [['Non renseigné',"Non renseigné"], ['Oui',"Oui"], ['Non',"Non"]], {:selected =&gt; (@camping.caracteristiquetest.piscine?)}, {class:"form-control", id:"exampleSelect1"}) %&gt;
</code></pre>

<p><strong>EDIT</strong>
development.log</p>

<pre><code>  Started GET "/campings/1" for 127.0.0.1 at 2016-08-28 14:06:56 +0200
Processing by CampingsController#show as HTML
  Parameters: {"id"=&gt;"1"}
  [1m[36mCamping Load (1719.1ms)[0m  [1m[34mSELECT  "campings".* FROM "campings" WHERE "campings"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
  [1m[36mCACHE (0.0ms)[0m  [1m[34mSELECT  "campings".* FROM "campings" WHERE "campings"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
  Rendering campings/show.html.erb within layouts/application
  [1m[36mCaracteristiquetest Load (0.0ms)[0m  [1m[34mSELECT  "caracteristiquetests".* FROM "caracteristiquetests" WHERE "caracteristiquetests"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
  [1m[36mProprietaire Load (0.0ms)[0m  [1m[34mSELECT  "proprietaires".* FROM "proprietaires" WHERE "proprietaires"."id" = ? LIMIT ?[0m  [["id", 7], ["LIMIT", 1]]
  [1m[36mCamping Load (1900.1ms)[0m  [1m[34mSELECT campings.*, (69.09332411348201 * ABS(campings.latitude - 48.52566299999999) * 0.7071067811865475) + (59.836573914187355 * ABS(campings.longitude - 3.664031) * 0.7071067811865475) AS distance, CASE WHEN (campings.latitude &gt;= 48.52566299999999 AND campings.longitude &gt;= 3.664031) THEN  45.0 WHEN (campings.latitude &lt;  48.52566299999999 AND campings.longitude &gt;= 3.664031) THEN 135.0 WHEN (campings.latitude &lt;  48.52566299999999 AND campings.longitude &lt;  3.664031) THEN 225.0 WHEN (campings.latitude &gt;= 48.52566299999999 AND campings.longitude &lt;  3.664031) THEN 315.0 END AS bearing FROM "campings" WHERE (campings.latitude BETWEEN 48.38093121688914 AND 48.67039478311084 AND campings.longitude BETWEEN 3.445496852835473 AND 3.8825651471645273 AND campings.id != 1) ORDER BY distance ASC[0m
  [1m[36mProprietaire Load (1.0ms)[0m  [1m[34mSELECT  "proprietaires".* FROM "proprietaires" WHERE "proprietaires"."id" = ? ORDER BY "proprietaires"."id" ASC LIMIT ?[0m  [["id", 7], ["LIMIT", 1]]
  Rendered campings/show.html.erb within layouts/application (2184.1ms)
  Rendered campings/index.html.erb within layouts/application (19341.1ms)
  Rendered devise/menu/_registration_items.html.erb (1.0ms)
  Rendered devise/menu/_login_items.html.erb (1.0ms)
  Rendered layouts/partials/_nav.html.erb (100.0ms)
  Rendered layouts/partials/_messages.html.erb (1.0ms)
  [1m[36mProprietaire Load (0.0ms)[0m  [1m[34mSELECT  "proprietaires".* FROM "proprietaires" WHERE "proprietaires"."id" = ? ORDER BY "proprietaires"."id" ASC LIMIT ?[0m  [["id", 7], ["LIMIT", 1]]
  Rendered layouts/partials/_footer.html.erb (1.0ms)
  Rendered devise/menu/_registration_items.html.erb (5.0ms)
Completed 200 OK in 8799ms (Views: 1524.3ms | ActiveRecord: 3620.2ms)


  Rendered devise/menu/_login_items.html.erb (0.0ms)
  Rendered layouts/partials/_nav.html.erb (75.0ms)
  Rendered layouts/partials/_messages.html.erb (1.0ms)
  Rendered layouts/partials/_footer.html.erb (1.0ms)
Completed 200 OK in 20182ms (Views: 19855.4ms | ActiveRecord: 2.0ms)


Started GET "/campings/1/edit" for 127.0.0.1 at 2016-08-28 14:07:08 +0200
Processing by CampingsController#edit as HTML
  Parameters: {"id"=&gt;"1"}
  [1m[36mCamping Load (0.0ms)[0m  [1m[34mSELECT  "campings".* FROM "campings" WHERE "campings"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
  [1m[36mProprietaire Load (0.0ms)[0m  [1m[34mSELECT  "proprietaires".* FROM "proprietaires" WHERE "proprietaires"."id" = ? ORDER BY "proprietaires"."id" ASC LIMIT ?[0m  [["id", 7], ["LIMIT", 1]]
  Rendering campings/edit.html.erb within layouts/application
  [1m[36mCaracteristiquetest Load (1.0ms)[0m  [1m[34mSELECT  "caracteristiquetests".* FROM "caracteristiquetests" WHERE "caracteristiquetests"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
  Rendered campings/_form.html.erb (12.0ms)
  Rendered campings/edit.html.erb within layouts/application (61.0ms)
  Rendered devise/menu/_registration_items.html.erb (1.0ms)
  Rendered devise/menu/_login_items.html.erb (1.0ms)
  Rendered layouts/partials/_nav.html.erb (51.0ms)
  Rendered layouts/partials/_messages.html.erb (0.0ms)
  Rendered layouts/partials/_footer.html.erb (1.0ms)
Completed 200 OK in 487ms (Views: 463.3ms | ActiveRecord: 1.0ms) 
  Started PATCH "/campings/1" for 127.0.0.1 at 2016-08-28 14:07:18 +0200
Processing by CampingsController#update as HTML
  Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"1H6bsZ6d5Z8HVa0X8hUp0LQUg+SdU6CmqUEIrP7eSip0f3yVnzKlaPojwYz+AGS9a4wz4LtVeZU10G70TEIt2g==", "camping"=&gt;{"name"=&gt;"DOMAINE DE LA NOUE DES ROIS", "adresse"=&gt;"rue machin", "code_postale"=&gt;"10100", "commune"=&gt;"ma commune", "courriel"=&gt;"email@email.com", "site_internet"=&gt;"www.exemple.com", "tel"=&gt;"0101010101", "description"=&gt;"ma description", "etoile"=&gt;"3", "piscine"=&gt;"Non"}, "commit"=&gt;"Enregistrer", "id"=&gt;"1"}
  [1m[36mCamping Load (0.0ms)[0m  [1m[34mSELECT  "campings".* FROM "campings" WHERE "campings"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
  [1m[36mProprietaire Load (1.0ms)[0m  [1m[34mSELECT  "proprietaires".* FROM "proprietaires" WHERE "proprietaires"."id" = ? ORDER BY "proprietaires"."id" ASC LIMIT ?[0m  [["id", 7], ["LIMIT", 1]]
Unpermitted parameter: piscine
Completed 400 Bad Request in 5ms (ActiveRecord: 1.0ms)



ActionController::ParameterMissing (param is missing or the value is empty: caracteristiquetest):

app/controllers/campings_controller.rb:111:in `camping_params'
app/controllers/campings_controller.rb:82:in `block in update'
app/controllers/campings_controller.rb:81:in `update'
  Rendering C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout
  Rendering C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_source.html.erb
  Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (6.0ms)
  Rendering C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb
  Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.0ms)
  Rendering C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
  Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)
  Rendered C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actionpack-5.0.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (1753.1ms)
</code></pre>

<p><strong>EDIT2</strong></p>

<p>I added attr_accessor :piscine on camping.rb but i have same error</p>

<hr>

<p><strong>EDIT3</strong>
I add this on my controller</p>

<pre><code>(... :image, caracteristiquetest_attributes: [:piscine, :barbecue])
</code></pre>

<p>But I have always Always unpermitted paramter :piscine</p>

<p>development.log</p>

<pre><code>  Started PATCH "/campings/1" for 127.0.0.1 at 2016-08-28 17:24:27 +0200
    Processing by CampingsController#update as HTML
      Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"I7otqLV4d8oqWdCncp5yeZK1tX/NeijUMHpA+XtH+zGDu8qMtNc3PdcvvDx+iz8UTS0Fe+t88ees6yahyducwQ==", "camping"=&gt;{"name"=&gt;"nomducamp", "adresse"=&gt;"adresse1", "code_postale"=&gt;"10100", "commune"=&gt;"SAINT-HILAIRE-SOUS-ROMILLY", "courriel"=&gt;"mail@mail.com", "site_internet"=&gt;"www.example.com", "tel"=&gt;"0101010101", "description"=&gt;"desc", "etoile"=&gt;"3", "piscine"=&gt;"Non renseigné"}, "commit"=&gt;"Enregistrer", "id"=&gt;"1"}
      [1m[36mCamping Load (0.0ms)[0m  [1m[34mSELECT  "campings".* FROM "campings" WHERE "campings"."id" = ? LIMIT ?[0m  [["id", 1], ["LIMIT", 1]]
      [1m[36mProprietaire Load (0.0ms)[0m  [1m[34mSELECT  "proprietaires".* FROM "proprietaires" WHERE "proprietaires"."id" = ? ORDER BY "proprietaires"."id" ASC LIMIT ?[0m  [["id", 7], ["LIMIT", 1]]
    Unpermitted parameter: piscine
      [1m[35m (0.0ms)[0m  [1m[36mbegin transaction[0m
      [1m[35m (1.0ms)[0m  [1m[36mcommit transaction[0m
    Redirected to http://localhost:3000/campings/1
    Completed 302 Found in 579ms (ActiveRecord: 1.0ms)
</code></pre>

<p>What can i do ? I m lost...</p>