Select_tag question
Rails 2.3.11
I'm trying to add a drop-do开发者_开发百科wn "sort by" switch to a page. The page determines how to sort the items in the list by a URL argument (http://.../places?sort=name). How would I have a drop-down menu that, when changed, goes to the appropriate page?
"Name" -> ?sort=name
"Category" -> ?sort=cat
"Abbreviation" -> ?sort=abbrev
"Building Number" -> ?sort=num
Those ^ are the mappings. I'm also not sure how to have the drop-down menu say one thing, but submit another.
Thank you!
options = options_for_select [['Name','name'],['Category','cat'],['Abbreviation','abbrev'],['Building Number','num']]
select_tag :sort, options
Basically you build the options out first by passing an Array of 2 element arrays where the first element is your display value, and the second element is the select value. options_for_select will generate all the options for you, which you can then pass to select_tag.
精彩评论