0

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

= 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)

4

3 回答 3

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
于 2013-06-06T12:18:45.007 回答
1

尝试这个:

= form_for @question 做 |w|
  %p
    %select{ :name => "问题[问题状态]" }
      %option{:value => 1}= "标签 1"
      %option{:value => 2}= "标签 2"      
  %p
    = w.submit "更新"
  %p
    = link_to '返回', :back
于 2013-06-06T08:30:49.647 回答
1

你可以这样做:

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

或者如果你想让它成为静态的

w.select :question_status, [['label1',value],['label2',value]]
于 2013-06-06T10:30:10.070 回答