Multi-model form problem

Posted by raphael_turtle on Stack Overflow See other posts from Stack Overflow or by raphael_turtle
Published on 2010-05-13T15:37:33Z Indexed on 2010/05/13 22:14 UTC
Read the original article Hit count: 156

Filed under:
|

(I'm just learning rails so....) I have a photo model and a gallery model, habtm associations and a join table. I'm making a photo gallery. The gallery page has a title field and description field. User creates gallery title, then goes to the photo page and checkboxes each image they want in that gallery.

I get the error "undefined method `to_i' for ["1", {"title"=>"1"}]:Array" when trying to save/update a photo with a gallery title(with the checkbox)

<% form_for @photo, :html => {:multipart => true } do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :title %>
    <%= f.text_field :title %>
  </p>

  <p>
    <%= f.label :description %>
    <%= f.text_area :description %>
  </p>
  <p>
    <%= f.label :image %>
    <%= f.file_field :image %>
  </p>


<% for gallery in @photo.galleries %>
<% fields_for "painting[gallery_attributes][]", gallery do |g| %>
<div>
  <%= g.check_box :title %>
  <%= gallery.title %>
</div>
<% end %>
<% end %>
<p><%= submit_tag 'Update' %></p>
<% end %>

How much of this is horribly wrong? Can someone point me in the right direction?, I can't find any tutorials relating to this for 2.3 and above.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about forms