Haml form_for下拉列表

时间:2013-06-06 07:45:12

标签: ruby-on-rails haml form-for

我无法在我的视图中显示下拉列表。 这是我的编辑操作表单。

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

我有这个错误:wrong number of arguments (1 for 2)

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:1)

你可以这样做:

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

或者如果你想让它静止

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

答案 2 :(得分: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