开发者

Adding both a collection and a custom field to a Select Box

I am making a select box, and I'm using a collection in it. But at the top of all the 开发者_StackOverflow中文版selections I want to add something that otherwise wouldn't be in that collection.

Here is my select box :

  = select (@organization, "tabs", @organization.tabs.collect { |t| [t.title, t.id] }, {}, {:class => "text_tab_link"} )

And I would like to add the words About and Edit as an additional selection at the top of the collection.

Anyone know how to pimp a select box?


Something like this perhaps? Choose the special ids as appropriate.

@custom = [ ["About", -1], ["Edit", -2] ]

= select (@organization, "tabs", (@custom + @organization.tabs.collect { |t| [t.title, t.id] }), {}, {:class => "text_tab_link"})


Another variant

select (@organization, "tabs", options_for_select(["Partial", "Exact"])+
  options_from_collection_for_select(@organization.tabs, "title", "id"), {}, {:class => "text_tab_link"} )
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜