【问题标题】:Formtastic + nested categoriesFormtastic + 嵌套类别
【发布时间】:2011-03-02 19:04:02
【问题描述】:

我有一个文章模型和一个类别模型。类别充当树。

构建选择列表以允许管理员从选择列表中选择一个类别以便稍后将其与文章关联的最佳方法是什么?

semantic_form_for(@article) do |f|
  f.input :title, :as => :string
  f.input :content, :as => :text
  f.input :category, :collection => #what should go here ?
end

【问题讨论】:

  • 8 年后,你有没有想过这个问题? :p

标签: ruby-on-rails nested-sets formtastic


【解决方案1】:

试试这个:

f.input :category, :as => :select, :collection => Category.all

或者,您可以将它们指定为(来自文档):

f.input :category,  :as => :select, :collection => { @cat1.name => @cat1id, @cat2.name => @cat2.id }
f.input :category,  :as => :select, :collection => ["cat1", "cat2", "cat3", "cat4", "cat5"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多