Wednesday, December 26, 2012

[Rails] Re: Multiple checkboxes for a has_many through not saving

On Dec 26, 12:15 am, why-el <wael.khobala...@gmail.com> wrote:
>
> I appended the word "attributes" bellow to the language_background model in
> the hope that the books_ids array gets inserted properly into the params
> hash with the other attributes. Inspecting the development.log, I can see
> the key language_background_and_interest_attributes twice: One for all the
> other data which get successfully saved, and one for the book_ids array
> which apparently gets ignored. Any ideas?
>

What does that log look like? You'd probably need to nest it in the
hash for the parent attributes ie
some_model[language_background_and_interest_attributes][some_id]
[book_ids]

The some_id for a saved record would be just its id. If you're adding
fields on the fly, then you'll have to have the matching id - check
what other parameters get submitted

Fred


>     <%= f.fields_for :language_background_and_interest do |builder| %>
>       <div class="field">
>       <%= hidden_field_tag "language_background_and_interest_attributes[book_ids][]" %>
>       <% Book.all.each do |book| %>
>         <br><%= check_box_tag "language_background_and_interest_attributes[book_ids][]", book.id %>
>         <%= book.name.humanize %>
>       <% end %>
>       </div>
>     <% end %>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate