2012-06-21 50 views
0

,並有這樣的代碼:做一個選擇顯示我使用的軌道當前選定的選項

<%= select_tag :tag, options_for_select(["Politics", "Technology", "Entertainment", 
    "Sports", "Science", "Crime", "Business", "Social", "Nature", "Other"]), :selected => 
    "Politics" %> 

:selected部分顯然不是一個有效的選擇,但它轉發我希望做的。代替"Politics"應該是當前選擇的選項(我知道如何做這部分)。但更重要的是,默認選項有什麼選項突出顯示選擇選項?

回答

3

默認選擇的選項在option_for_select方法

第二個屬性的方法接受是元件應選擇說明。

options_for_select(container, selected = nil) 

所以你的情況,該代碼將是:

<%= select_tag :tag, options_for_select(["Politics", "Technology", "Entertainment", 
    "Sports", "Science", "Crime", "Business", "Social", "Nature", "Other"], "Politics") %> 
相關問題