Reputation: 327
I want to create a custom input for formtasic that uses a custom collection
My collection is returned by MyModule::Categories.all
I'm extending SelectInput
class CategoriesSelectInput < Formtastic::Inputs::SelectInput
def select_html
collection = MyModule::Categories.all
builder.select(input_name, collection, input_options, input_html_options)
end
end
but the formatting seems to get lost, where am I going wrong?
Upvotes: 1
Views: 895
Reputation: 21
It's a bit late.. but try this way:
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
Upvotes: 2
Reputation: 1954
There is no need to extend select input. Formatstic has awesome support for providing custom collections. Read it's documentation for details: https://github.com/justinfrench/formtastic
In short, you can do something like this:
<%= f.input :some_id, :as => :select, :collection => MyModule::Categories.all %>
Upvotes: -1