I have this select drop down menu that I would like to have either show default values for the menu or have it grab from the database the values already selected (as the user can change their selections anytime they want). I imagine that I would have to be using an id somewhere, but Im just not sure on where to even start. Here is my code for the select: <%= select ''airlineinfo'', ''smoking'', [[''Non-Smoking''], [''Smoking''] ] %> Pretty straight forward. airlineinfo is the name of the table in the database and smoking is the name. Thanks, ~S -- 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 -~----------~----~----~----~------~----~------~--~---
Shandy Nantz wrote:> I have this select drop down menu that I would like to have either show > default values for the menu or have it grab from the database the values > already selected (as the user can change their selections anytime they > want). I imagine that I would have to be using an id somewhere, but Im > just not sure on where to even start. Here is my code for the select: > > <%= select ''airlineinfo'', ''smoking'', [[''Non-Smoking''], [''Smoking''] ] %> > > Pretty straight forward. airlineinfo is the name of the table in the > database and smoking is the name. Thanks, > > ~Swhat are the values in the db? is this a boolean field ( smoking -> true / false ) or a text field? if it is a simple yes / no smoking option (boolean) you could use a checkbox rather than a select ... if you need a select box, the way to go is using the below; (select_tag:) #creates the <select> html tag http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M000604 (options_from_collection_for_select:) #creates the html options tags http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000511 OR (options_for_select:) http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html#M000510 ========in the end u''d do something like:=========== select_tag ''airlineinfo[smoking]'', options_from_collection_for_select(@fliers, ''id'', ''flier_name'') or whatever suits your needs (which i haven''t really understood) anyway... hth ... -- 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 -~----------~----~----~----~------~----~------~--~---
I guess the idea that I''m trying to convey is that a user can go and fill out their preferences for seating, smoking, etc., in a form. Later, if they so choose too, they can edit or change the values that they have made in that form, switch their window seat preferences to aisle, for example. What I would like to happen is for their original preferences to be visable every time they go back to modify the form (or any changes that are made). This way, to me, it just re-assures the user that the values they entered in the original filling out of the form took and were saved. The way the form is set-up now, however, is to show the default values in the select boxes whenever the user goes back to visit that form. -- 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 -~----------~----~----~----~------~----~------~--~---
This sounds like an html question! I haven''t tried this, frankly, but seeing how most of the options that goes under helper class methods seem to be html options themselves, you might try this: <%= select_tag ''airlineinfo'', ''smoking'', [[''Non-Smoking''], [''Smoking''] ], :selected=>''Smoking'' %> Or even better: <%= select_tag ''airlineinfo'', ''smoking'', [[''Non-Smoking''], [''Smoking''] ], :selected=>airlineinfo.smoking.to_s %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes, thank you again, that works perfectly. -- 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 -~----------~----~----~----~------~----~------~--~---
Whoa, it actually worked!? COOL :-)! I only guessed. On Aug 8, 11:10 am, Shandy Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Yes, thank you again, that works perfectly. > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---