我的表格中有这个:
<%= 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
为什么不填充字段?
最佳答案
我相信您可以简单地在 [#select][1]
中传递一个数组。您不需要调用选项来收集。我还认为,如果这是一个模型表单,您可以忽略 :selected
选项,Rails 将使用属性值来计算它。
试试这个:
<%= f.select :status, Article::STATUS, :include_blank => true, :class => 'select_field' %>
关于html - 如何使用 Rails 在编辑页面中填充选择框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11720371/