Note that there are some explanatory texts on larger screens.

plurals
  1. PORails4: ForbiddenAttributesError on Model Update
    text
    copied!<p>I get a ForbiddenAttributesError when I send an update to my Rails 4 controller.</p> <p>The model is 'Company' and it has a private method in it's controller:</p> <pre><code> def company_params params.require(:company).permit( :adress_id, :name, :zusatz, :kontakt, :strasse, :adresszusatz, :plz, :ort, :telefon, :fax, :natel, :email, :alternative_email, :url, :anbieter_id, :eintrittsdatum, :betrag, :bemerkungen, :betrag_gwrj, :betrag_sgkv, :rechnungszusatz, :zusatzfeld_7, :zusatzfeld_8, :zusatzfeld_9, :zusatzfeld_10, :datum_mutation, :verzeichnis_id, :industry_ids =&gt; []#, #:latitude, #:longitude ) end </code></pre> <p>BetterErrors shows me these Request parameters:</p> <pre><code>{"utf8"=&gt;"✓", "_method"=&gt;"patch", "authenticity_token"=&gt;"0rDHB7BNuHikL3/Fktdaj6BFFDinpUwPdpy+12HdMw4=", "company"=&gt;{"adress_id"=&gt;"", "name"=&gt;"AGIP Tankstelle Rapperswil", "zusatz"=&gt;"", "kontakt"=&gt;"Eni Suisse S.A.", "strasse"=&gt;"Zürcherstrasse 92", "adresszusatz"=&gt;"", "plz"=&gt;"8640", "ort"=&gt;"Rapperswil", "telefon"=&gt;"", "fax"=&gt;"", "natel"=&gt;"", "email"=&gt;"", "url"=&gt;"", "anbieter_id"=&gt;"", "eintrittsdatum"=&gt;"", "betrag"=&gt;"", "bemerkungen"=&gt;"", "betrag_gwrj"=&gt;"", "betrag_sgkv"=&gt;"", "rechnungszusatz"=&gt;"", "zusatzfeld_7"=&gt;"test", "zusatzfeld_8"=&gt;"", "zusatzfeld_9"=&gt;"", "zusatzfeld_10"=&gt;"", "datum_mutation"=&gt;"", "verzeichnis_id"=&gt;"HR &amp; Stadt", "alternative_email"=&gt;""}, "commit"=&gt;"Speichern", "action"=&gt;"update", "controller"=&gt;"companies", "id"=&gt;"375"} </code></pre> <p>The form looks like this:</p> <pre><code>... &lt;%= form_for @company, url: {action: "update"}, html: {class: "form-horizontal"} do |f| %&gt; &lt;div class="col-md-6"&gt; &lt;div class="form-group"&gt; &lt;%= f.label :adress_id %&gt; &lt;%= f.text_field :adress_id %&gt; &lt;/div&gt; ... &lt;%= f.submit "Speichern" %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>And this is the Update Method in the controller:</p> <pre><code>def update @company = Company.find(params[:id]) if @company.update_attributes(params[:company]) redirect_to(@company) else render :edit end end </code></pre> <p>If I use the "company" hash in the rails console and create a company via Company.create [hash], it works fine. Any idea why Rails is throwing this error at me?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload