How can I use select_tag to 1. Have a prompt like "Select a Value" ( selected by default ) I tried this but did not work: <%= select_tag :current_course, options_for_select( Course.find(:all).map {|p| [p.title,p.id]} ), { :prompt => "Select a Value" } %> 2. Generate a ''selected'' event so that some action can be done like submit the form or refresh the page? Thanks in advance - AJ -- 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 -~----------~----~----~----~------~----~------~--~---
Abhishek Jain wrote:> How can I use select_tag to > > 1. Have a prompt like "Select a Value" ( selected by default ) > I tried this but did not work: > <%= select_tag :current_course, > options_for_select( Course.find(:all).map {|p| > [p.title,p.id]} ), > { :prompt => "Select a Value" } > %>I do the find in the controller and feed the options_for_select two instance variables: the options collection and the selected value. e.g. select_tag(:priority, options_for_select(@courses, @selected_course)) @courses is just an array so you just put your "Select a Value" as the first entry. e.g., @courses = [["Select a Value", "Select a Value"]] Then push the results of the find onto @courses. > 2. Generate a ''selected'' event so that some action can be done like> submit the form or refresh the page?If I understand your question, you''ll want to use observe_field on the select_tag. It will fire an Ajax call back to the server when the value in the select changes. HTH, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton wrote:> Abhishek Jain wrote: >> How can I use select_tag to >> >> 1. Have a prompt like "Select a Value" ( selected by default ) >> I tried this but did not work: >> <%= select_tag :current_course, >> options_for_select( Course.find(:all).map {|p| >> [p.title,p.id]} ), >> { :prompt => "Select a Value" } >> %> > > I do the find in the controller and feed the options_for_select two > instance > variables: the options collection and the selected value. > e.g. select_tag(:priority, options_for_select(@courses, > @selected_course)) > @courses is just an array so you just put your "Select a Value" as the > first > entry. > e.g., @courses = [["Select a Value", "Select a Value"]] > Then push the results of the find onto @courses. > > > 2. Generate a ''selected'' event so that some action can be done like >> submit the form or refresh the page? > > If I understand your question, you''ll want to use observe_field on the > select_tag. It will fire an Ajax call back to the server when the value > in > the select changes. > > HTH, > BillHey Bill Thanks for the help. I could get the "prompt" in my selection list. I havent tried observe_field yet but will give that a shot. Thanks again - AJ -- 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 -~----------~----~----~----~------~----~------~--~---