我的形式是:
<%= f.select :status, options_for_select(Article::STATUS), :include_blank => true, :selected => @article.status, :class => 'select_field' %>
型号:
class Article < ActiveRecord::Base
attr_accessible :author, :content, :publication_date, :status, :title, :tag_tokens
attr_reader :tag_tokens
STATUS = ['Rascunho', 'Em Revisão', 'Publicado']
end
为什么不填充该字段?
答案 0 :(得分:3)
我相信你可以简单地在[#select][1]
中传递一个数组。您无需调用选项进行收集。我还认为如果这是一个模型表单,你可以省略:selected
选项,Rails会使用属性值来计算它。
试试这个:
<%= f.select :status, Article::STATUS, :include_blank => true, :class => 'select_field' %>