开发者

Select_tag question

开发者 https://www.devze.com 2023-03-14 09:08 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号