views:

11

answers:

1

Hi all,

I have a controller that has a value that I want to pass to the rhtml. I already managed to get the value correctly, and based on that, I need to do an action in the rhtml. For code snippets,

def getsubtable     
  @subtables = Haus.find(params[:bewohner_id])

from the method above, when I debugged it, I can get the correct value of "bewohner_id". (example : bewohner_id = "2" ). Now, I need to show a list of value that corresponds to bewohner_id ="2" in another form (getsubtable.rhtml). So, if I get a "2", I will show "a,b,c" in a new form

<% for subtable in @subtables %>
  <option value="<%= subtable.bewohner_id %>"><%= subtable.bewohner_id %></option>
<% end %>

however I got an error of

ActionView::TemplateError (undefined method 'each' for #haus) 

Please kindly guide me, how can I use the value of '2' from bewohner_id and use it in <option value> above

Thank you

A: 
Haus.find(params[:bewohner_id])

returns a single record, not a collection. If you want a collection you need to use

Haus.find_all_by_bewohner_id(params[:bewohner_id])

Also, use @subtables.each rather than for subtable in @subtables.

Simone Carletti