我想为使用自定义集合的formtasic创建自定义输入
我的收藏集由MyModule::Categories.all
返回
我正在扩展SelectInput
class CategoriesSelectInput < Formtastic::Inputs::SelectInput
def select_html
collection = MyModule::Categories.all
builder.select(input_name, collection, input_options, input_html_options)
end
结束
但是格式似乎丢失了,我要去哪里错了?
有点晚了。但是尝试这种方式:
class CategoriesSelectInput < Formtastic::Inputs::SelectInput
def to_html
collection = MyModule::Categories.all
builder.input input_name, as: :select, collection: collection, input_html: input_html_options
end
end
无需扩展选择输入。 Formatstic具有提供自定义集合的强大支持。请阅读文档以获取详细信息:https://github.com/justinfrench/formtastic
总之,您可以执行以下操作:
<%= f.input :some_id, :as => :select, :collection => MyModule::Categories.all %>