select in list.rhtml

i am new to ruby on rails, and this might be a simple one but i have no idea what to do. i need to put a select (_tag or whatever) into a list.rhtml and get the selected value from this. Putting the select to the view works fine. The displayed options are ok too, but i don't know how to get the selected option. What i have so far:

<% for calendar in @calendars %> <tr> <td><%= link_to "#{calendar.person.account}", { :controller => 'person', :action => 'list', :person_id => calendar.person.id } %></

<td><%= link_to "#{calendar.calendar_state.name}", { :controller => 'calendar', :action => 'list', :calendar_state_id => calendar.calendar_state } %></td> <td><%= select 'calendar', 'project_has_person_id', ProjectHasPerson.find(:all, :conditions => ["person_id = ?", calendar.person.id]).collect{ |p| [p.person.account + "@" + p.project.name, p.id]} %></td>

  <% for column in Calendar.content_columns %>     <td><%=h calendar.send(column.name) %></td>   <% end %>   <td><%= link_to 'assign', :action => 'assign', :id => calendar %></

  </tr> <% end %>

The calendar-entry has a column called project_has_person_id, but whenever i try to access the parameter in the controller with params[:project_has_person_id] the value will be nil.

Any help is appreciated!

Thanks

i am new to ruby on rails, and this might be a simple one but i have no idea what to do. i need to put a select (_tag or whatever) into a list.rhtml and get the selected value from this. Putting the select to the view works fine. The displayed options are ok too, but i don't know how to get the selected option. What i have so far:

<% for calendar in @calendars %> <tr> <td><%= link_to "#{calendar.person.account}", { :controller => 'person', :action => 'list', :person_id => calendar.person.id } %></ > <td><%= link_to "#{calendar.calendar_state.name}", { :controller => 'calendar', :action => 'list', :calendar_state_id => calendar.calendar_state } %></td> <td><%= select 'calendar', 'project_has_person_id', ProjectHasPerson.find(:all, :conditions => ["person_id = ?", calendar.person.id]).collect{ |p| [p.person.account + "@" + p.project.name, p.id]} %></td>

<% for column in Calendar.content_columns %>    <td><%=h calendar.send(column.name) %></td> <% end %>        <td><%= link_to 'assign', :action => 'assign', :id => calendar %></ > </tr> <% end %>

The calendar-entry has a column called project_has_person_id, but whenever i try to access the parameter in the controller with params[:project_has_person_id] the value will be nil.

I suspect that the value is in params[:calendar][:project_has_person_id].

The development log will show you all of the values of the params object.

Citando marco <marco.steffan@gmail.com>:

i am new to ruby on rails, and this might be a simple one but i have no idea what to do. i need to put a select (_tag or whatever) into a list.rhtml and get the selected value from this. Putting the select to the view works fine. The displayed options are ok too, but i don't know how to get the selected option. What i have so far:

<% for calendar in @calendars %> <tr> <td><%= link_to "#{calendar.person.account}", { :controller => 'person', :action => 'list', :person_id => calendar.person.id } %></ > <td><%= link_to "#{calendar.calendar_state.name}", { :controller => 'calendar', :action => 'list', :calendar_state_id => calendar.calendar_state } %></td> <td><%= select 'calendar', 'project_has_person_id', ProjectHasPerson.find(:all, :conditions => ["person_id = ?", calendar.person.id]).collect{ |p| [p.person.account + "@" + p.project.name, p.id]} %></td>

  <% for column in Calendar.content_columns %>     <td><%=h calendar.send(column.name) %></td>   <% end %>   <td><%= link_to 'assign', :action => 'assign', :id => calendar %></ >   </tr> <% end %>

The calendar-entry has a column called project_has_person_id, but whenever i try to access the parameter in the controller with params[:project_has_person_id] the value will be nil.

Any help is appreciated!

You might be interessed in this article: Buckblog: Skinny Controller, Fat Model

Sorry for my poor English.

HTH,

Davi Vidal

thank you for your reply. i have tried your solution, but it didn't work either. is there really no way to pass a selected value coming from a selection to a controller?

marco

Hi macro,

Try to place your select statement inside a form tag instead of link_to, only then it submits the selection to the controller. Then you need to access the selection by params[:calendar] [:project_has_person_id] as stated by Christopher.

Thanks, Kiran. http://kiran.gnufied.org

Thanks a lot Kiran! That did exactly what i want.

marco