Currently I have a list of clients with a link next to each one so I can add a new task for that particular client. When I click the link to go to the new task view page I''d like to retain the clients_id so that it can be pre-selected in the pulldown menu which allows me to assign a client otherwise. I can see the client_id being passed in the url and I can render it on the new task form page by using <%= @client_id %> but using a select menu or collection_select the client_id is not preselected. Specifically, In my client list view I have this: <%= link_to ''add task'', { :action => ''new'', :controller => "tasks", :client_id => client.id } %> In my task controller in the new function definition I have: @client_id = params[:client_id] And in the task form I''m using this to create a pulldown menu of client company names: <%= select(''task'', ''client_id'', all_clients.collect {|p| [ p.company_name, p.id ] } ) %> At first I was trying to use collection_select since it seemed easier but that didn''t work either. I hope this doesn''t seem too vague or basic or something to answer. Any help or pointers appreciated. DAN -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2006-Nov-04 21:53 UTC
Re: newbie: Can I preselect pulldown option from passed in v
If you use select(''task'', ''client_id'', ...) Then the drop down will preselect the value given by calling the client_id method on @task, so set @task.client_id to the value passed through the params and you should be ok. Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks! Adding <% @task.client_id = @client_id %> above the form did the trick. DAN -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Hall
2006-Nov-06 01:14 UTC
Re: newbie: Can I preselect pulldown option from passed in var?
:select => @client_id in the html options hash http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000399 On 11/4/06, DAN <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Currently I have a list of clients with a link next to each one so I can > add a new task for that particular client. > > When I click the link to go to the new task view page I''d like to retain > the clients_id so that it can be pre-selected in the pulldown menu which > allows me to assign a client otherwise. > > I can see the client_id being passed in the url and I can render it on > the new task form page by using <%= @client_id %> but using a select > menu or collection_select the client_id is not preselected. > > Specifically, > > In my client list view I have this: > <%= link_to ''add task'', { :action => ''new'', :controller => "tasks", > :client_id => client.id } %> > > In my task controller in the new function definition I have: > @client_id = params[:client_id] > > And in the task form I''m using this to create a pulldown menu of client > company names: > <%= select(''task'', ''client_id'', all_clients.collect {|p| [ > p.company_name, p.id ] } ) %> > > At first I was trying to use collection_select since it seemed easier > but that didn''t work either. > > I hope this doesn''t seem too vague or basic or something to answer. Any > help or pointers appreciated. > > DAN > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---