2

How can I create select with grouped options with simple_form from table, not from collection ? Tried:

= f.input :countries, 
:collection => [["North America",[["United States","US"],["Canada","CA"]]]], 
:as => :grouped_select

but got error: nil is not a symbol

2 Answers 2

4

A quick look at the documentation on https://github.com/plataformatec/simple_form shows that you need a :group_method => :method on the collection_select.

Here's the complete example they give: f.input :country_id, :collection => @continents, :as => :grouped_select, :group_method => :countries

Also, just in case you didn't know, simple_form has a country_select helper and you need to add gem 'country_select' to your gemfile if you plan on using it.

A country_select using that helper might look like this: f.input :shipping_country, :priority => [ "Brazil" ] with an option to restrict the list to just a few countries like so: f.input :shipping_country, :priority => [ "Brazil" ], :collection => [ "Australia", "Brazil", "New Zealand"] Those examples were found in the simple_form docs in the "priority" section: http://rubydoc.info/github/plataformatec/simple_form/master/frames. Apparently, simple_form will detect it's for a country, so just using input should suffice.

Sign up to request clarification or add additional context in comments.

Comments

0

In my case, only worked when I used as: :grouped_select and :group_method => :last

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.