simple_fields_for how to create collection #570

kakubei opened this Issue May 10, 2012 · 2 comments


None yet
3 participants

kakubei commented May 10, 2012

My apologies if this is not the right place to ask this, but I have the following form:

= f.fields_for :category do |category_form|
= category_form.text_field :category

This produces an input field since it's a many to one relationship I have established.

I'd like to create a select dropdown menu like it does for many to many relationships. So I tried:

= f.fields_for :category do |category_form|
= category_form.text_field :category, :as => :select

Which produces a select with an empty value and just "yes/no" as the options.

So the question is, how to I populate the collection so that it displays the categories from the table?

I did not find anything in the readme that addresses this and if I try to do something like:

= f.fields_for :category do |category_form|
= category_form.text_field :category, :as => :select, :collection => :category

I get an error: undefined method 'to_a' for :category:Symbol



carlosantoniodasilva commented May 10, 2012

You can use the association helper instead of fields_for:

f.association :category

Or you have to give the :collection manually with an array of values:

f.input :category_id, :collection => Category.all

If you have more questions, please send them to the mailing list, there's a link on the Readme.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment