2010-08-19 133 views
2

我正在創建一個選擇框,並在其中使用集合。但在所有選擇的頂部,我想添加一些否則不在該集合中的東西。將集合和自定義字段添加到選擇框

這是我的選擇框:

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

而且我想補充的話AboutEdit在資料收集的頂部還有一個選擇。

任何人都知道如何皮條客選擇框?

回答

4

也許這樣的事情?根據情況選擇特殊的ID。

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

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

感謝這麼多的朋友。對此,我真的非常感激。 – Trip 2010-08-19 14:54:48

1

另一個變種

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