Note that there are some explanatory texts on larger screens.

plurals
  1. POparams.require().permit does not work as expected
    primarykey
    data
    text
    <p>I have this controller</p> <pre><code>class PeopleController &lt; ApplicationController def new @person = Person.new @person.phones.new end # this is the action that gets called by the form def create render text: person_params.inspect # @person = Person.new(person_params) # @person.save # redirect_to people_path end def index @person = Person.all end private def person_params params.require(:person).permit(:name, phones_attributes: [ :id, :phone_number ]) end end </code></pre> <p>and this view</p> <pre><code>&lt;%= form_for :person, url: people_path do |f| %&gt; &lt;p&gt; &lt;%= f.label :name %&gt;&lt;br /&gt; &lt;%= f.text_field :name %&gt; &lt;/p&gt; &lt;%= f.fields_for :phones do |f_phone| %&gt; &lt;div class="field"&gt; &lt;p&gt; &lt;%= f_phone.label :phone_number %&gt;&lt;br /&gt; &lt;%= f_phone.text_field :phone_number %&gt; &lt;/p&gt; &lt;/div&gt; &lt;% end %&gt; &lt;p&gt; &lt;%= f.submit %&gt; &lt;/p&gt; &lt;% end %&gt; </code></pre> <p>When I fill out both form fields and hit "Save Person" I only get <code>{"name"=&gt;"foo"}</code> - the phone number seems to vanish.</p> <p>However, when I change <code>phones_attributes</code> to <code>phones</code> I get <code>{"name"=&gt;"foo", "phones"=&gt;{"phone_number"=&gt;"123"}}</code> (this would however cause problems with the create function.</p> <p>What's wrong here?</p> <p>Please note that this question is strongly related to that one: <a href="https://stackoverflow.com/questions/17558309/accepts-nested-attributes-for-what-am-i-doing-wrong">accepts_nested_attributes_for: What am I doing wrong</a> as well as to this posting: <a href="https://groups.google.com/forum/#!topic/rubyonrails-talk/4RF_CFChua0" rel="nofollow noreferrer">https://groups.google.com/forum/#!topic/rubyonrails-talk/4RF_CFChua0</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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