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> <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 %></ td> </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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Jul 24, 2008 at 8:04 AM, marco <marco.steffan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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> > <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 %></ > td> > </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.> Any help is appreciated! > > Thanks > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
davividal-UiHwsRqXctc1RhZgQKG/ig@public.gmane.org
2008-Jul-24 17:28 UTC
Re: select in list.rhtml
Citando marco <marco.steffan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > 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> > <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 %></ > td> > </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: http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model Sorry for my poor English. HTH, Davi Vidal --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On 24 Jul., 19:22, "Christopher Kintner" <kint...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jul 24, 2008 at 8:04 AM, marco <marco.stef...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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> > > <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 %></ > > td> > > </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. > > > Any help is appreciated! > > > Thanks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Jul 28, 3:41 pm, marco <marco.stef...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > On 24 Jul., 19:22, "Christopher Kintner" <kint...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Thu, Jul 24, 2008 at 8:04 AM, marco <marco.stef...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > 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> > > > <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 %></ > > > td> > > > </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. > > > > Any help is appreciated! > > > > Thanks--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---