2013-06-06 35 views

回答

1

試試這個:

= form_for @question do |w| 
    %p 
    %select{ :name => "question[question_status]" } 
     %option{:value => 1}= "label 1" 
     %option{:value => 2}= "label 2"  
    %p 
    = w.submit "Update" 
    %p 
    = link_to 'Back', :back
+0

edit.html.haml:3:語法錯誤,意想不到tASSOC,期待 '}' –

+0

變化到這個' = w.select 「question_status」 %選項{:值=> 1} =「標籤1「 %option {:value => 2} =」label 2「 錯誤的參數數量(1代表2) –

+0

測試我自己的實例並更正了'select'行。現在應該工作。 –

0

你可以這樣說:

w.select :question_status, @question.map {|q| [q.label,q.value] } 

,或者如果你想讓它靜態

w.select :question_status, [['label1',value],['label2',value]] 
1

我認爲這應該爲你工作,讓我知道這些關切。

= form_for @question do |w| 
    %p 
    = w.select "question_status", [["1", "label 1"], ["2", "label_2"]] 
    %p 
    = w.submit "Update" 
    %p 
    = link_to 'Back', :back