A simple syntax problem, I''m sure, but I could really use some help. I''m following the habtm checkbox page on the wiki: http://wiki.rubyonrails.com/rails/pages/CheckboxHABTM I have items in a habtm relationship with formats. The view looks like this: <ul> <% item.item_type.formats.each do |fmt| %> <li><%= check_box_tag("item[format_ids][]", fmt.id, @item.formats.include?(fmt)) %> <%= h(fmt.name) %></li> <% end %> </ul> As you would expect, this produces something like this: <li><input checked="checked" id="item[format_ids][]" name="item[format_ids][]" type="checkbox" value="1" />CD</li> I''m using update_attributes in the controller, but breakpoint reveals this error message: ActiveRecord::RecordNotFound: Couldn''t find Format with ID=#<Format:0x22744a0> I''m running: rails (0.14.2, 0.13.1, 0.12.1) Obviously something is going wrong getting the id... but I can''t understand what. Can anyone please help? Thanks, Rob
Robert Wheaton wrote:> A simple syntax problem, I''m sure, but I could really use some help. > > I''m following the habtm checkbox page on the wiki: > http://wiki.rubyonrails.com/rails/pages/CheckboxHABTM > > I have items in a habtm relationship with formats. > > The view looks like this: > <ul> > <% item.item_type.formats.each do |fmt| %> > <li><%= check_box_tag("item[format_ids][]", fmt.id, > @item.formats.include?(fmt)) %> > <%= h(fmt.name) %></li> > <% end %> > </ul> > > As you would expect, this produces something like this: > <li><input checked="checked" id="item[format_ids][]" > name="item[format_ids][]" type="checkbox" value="1" />CD</li> > > I''m using update_attributes in the controller, but breakpoint reveals > this error message: > ActiveRecord::RecordNotFound: Couldn''t find Format with > ID=#<Format:0x22744a0> > > I''m running: > rails (0.14.2, 0.13.1, 0.12.1) > > Obviously something is going wrong getting the id... but I can''t > understand what. Can anyone please help?Looks like it''s returning an object when you want an id (String value). Check fmt.id versus fmt Kev