Can anyone tell me why I''m getting the error "The error occured while evaluating nil.id_before_type_cast" for the following view code <% for entry in participant_portfolio.portfolio_entries -%> <%= select "entry[]" , :id, @buyer_profiles, :selected => entry.buyer_profile_id %> <% end -%> This seems to only happen when I use "entry[]" instead of just "entry". I need the id of the entry being written in the form and thus would prefer to use the "entry[]" method. Page 344 of AWDWR makes it look like it should work, but for some reason I can''t get it to. Any help is appreciated! Michael Jurewitz sinjin5@mac.com -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2413 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060421/9f7fb522/smime.bin
Mark Reginald James
2006-Apr-21 09:46 UTC
[Rails] Re: Forms Containing Collections problem
Michael Jurewitz wrote:> Can anyone tell me why I''m getting the error "The error occured while > evaluating nil.id_before_type_cast" for the following view code > > <% for entry in participant_portfolio.portfolio_entries -%> > <%= select "entry[]" , :id, @buyer_profiles, > :selected => entry.buyer_profile_id %> > <% end -%>AR form helpers operate on instance variables, so you need to use @entry rather than just entry in both your for statement and :selected option. -- We develop, watch us RoR, in numbers too big to ignore.
Mark Reginald James wrote:> Michael Jurewitz wrote:>> <% for entry in participant_portfolio.portfolio_entries -%> >> <%= select "entry[]" , :id, @buyer_profiles, >> :selected => entry.buyer_profile_id %> >> <% end -%> > > AR form helpers operate on instance variables, so you need to use > @entry rather than just entry in both your for statement and > :selected option.I have hacked this in the past by having the first line of the for block be @current_entry = entry so that for block creates a local var ''entry'' and I assign it to a member var, just so I can use the helpers. I assume there''s a much cleaner ay of doing this, but that works in a push. A. -- Posted via http://www.ruby-forum.com/.