RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: nickgnd
Yes, you can create a method in Country model that sorts the states by country_name and states_name (execute a query sql), and later call it in your form.
Example: if your new method is called "states_by_country_name_and_state_name"
in the form
<%= f.grouped_collection_select :state_id, Country.order(:name), :states_by_country_name_and_state_name, :name, :id, :name, include_blank: true %>