I''m using a dropdown on my form for a simple cms which displays the pages from the database. I want to add some options to the dropdown that are not in the database. Is there a way to do this? Here''s my code so far: <p><label for="navigation_link">Link</label><br/> <%= select("navigation", "link", Page.find_all.collect {|p| [ p.title, p.id ] }) %></p> What I want is to add in a link called "listings" that is not in the table as well as a link called "home". I''m giving the user the option to choose the display order, so it doesn''t matter where they show in the dropdown. However, it would be nice to have it still autoselect the appropriate item in the edit form. -- Posted via http://www.ruby-forum.com/.
try something like this: <select> <option value="home">Home</option> <%= option_groups_from_collection_for_select Page.find_all, ''id'', ''title'' %> </select> See: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000404 for more details. Hope that helps, Steve Greg Newman wrote:> I''m using a dropdown on my form for a simple cms which displays the > pages from the database. I want to add some options to the dropdown > that are not in the database. Is there a way to do this? > > Here''s my code so far: > > <p><label for="navigation_link">Link</label><br/> > <%= select("navigation", "link", Page.find_all.collect {|p| [ p.title, > p.id ] }) %></p> > > What I want is to add in a link called "listings" that is not in the > table as well as a link called "home". I''m giving the user the option > to choose the display order, so it doesn''t matter where they show in the > dropdown. However, it would be nice to have it still autoselect the > appropriate item in the edit form.-- Posted via http://www.ruby-forum.com/.
Worked like a charm. Thanks Steve! Stephen Bartholomew wrote:> try something like this: > <select> > <option value="home">Home</option> > <%= option_groups_from_collection_for_select Page.find_all, ''id'', > ''title'' %> > </select> > > See: > http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000404 > for more details. > > Hope that helps, > > Steve-- Posted via http://www.ruby-forum.com/.
Reasonably Related Threads
- Multiple Select example?
- how to get value from the post on the List page
- Can''t get select helper to populate dropdown w/default value
- How to Pass Jquery selected dropdown values and radio button values to controller
- Newbie: populate 2nd dropdown list based on user''s selection in 1st dropdown list