Forms Containing Collections problem

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 J.
[email protected]

Michael J. 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 J. wrote:

Michael J. 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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs