创建自定义输入形式选择

问题描述 投票:1回答:2

我想为使用自定义集合的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

结束

但是格式似乎丢失了,我要去哪里错了?

ruby-on-rails formtastic formbuilder
2个回答
0
投票

有点晚了。但是尝试这种方式:

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

-1
投票

无需扩展选择输入。 Formatstic具有提供自定义集合的强大支持。请阅读文档以获取详细信息:https://github.com/justinfrench/formtastic

总之,您可以执行以下操作:

<%= f.input :some_id, :as => :select, :collection => MyModule::Categories.all %>
© www.soinside.com 2019 - 2024. All rights reserved.