Note that there are some explanatory texts on larger screens.

plurals
  1. PONested Attributes not being saved
    primarykey
    data
    text
    <p>I have a form for creating/editing an event. There is a Client drop down which renders some custom questions and answers dependent on the selected Client.</p> <p>I'm running Rails 2.3.9 with Ruby 1.8.6 and Mongrel on Windows. Here is the relevant code:</p> <p>Event form</p> <pre><code>- form_for @event do |f| .... = f.collection_select(:client_id, Client.all, :id, :name) #custom_client_fields = render 'client_fields' if @client = observe_field :event_client_id, :url =&gt; {:action =&gt; 'client_fields'}, :with =&gt; "'client_id=' + encodeURIComponent(value)" .... </code></pre> <p>_client_fields.html.haml</p> <pre><code>- fields_for "event[client_attributes]", @client do |client| - client.fields_for :questions do |question| %label.question= question.object.content - question.fields_for :answers, Answer.new do |answer| = answer.text_field:content, :maxlength =&gt; 150, :size =&gt; 40 </code></pre> <p>Event Controller</p> <pre><code>def client_fields if params[:client_id].blank? render_no_client_fields #self explanatory else respond_to do |format| format.js { render :update do |page| page[:custom_client_fields].replace_html :partial =&gt; 'client_fields', :layout =&gt; false end } end end end </code></pre> <p>Parameter hash</p> <pre><code>Parameters: { "event"=&gt;{ "id"=&gt;"2", "client_attributes"=&gt;{ "questions_attributes"=&gt;{ "0"=&gt;{ "id"=&gt;"4", "answers_attributes"=&gt;{ "0"=&gt;{ "content"=&gt;"fjhkghjkk" } } } } } } } </code></pre> <p>Basically the form passes the validations and everything except the nested attributes. Nothing is inserted into the database table.</p> <p>Looking at the parameter hash my client_attributes doesn't have an id... hmmm...</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