Freddy Rangel
Freddy Rangel

Reputation: 1363

How to order a grouped collection select

Ok here's my problem. I have a dropdown of subcategories ordered by category. That's cool, but I really need to order subcategories as well. Here's the code in question:

<%= grouped_collection_select(:subcategory, :id, Category.order(:name), :populated_subcategories, :name, :id, :name, {}, { :class=> "form-control" }) %>

Upvotes: 0

Views: 48

Answers (1)

j-dexx
j-dexx

Reputation: 10406

If you set ordering on the association it should work I think.

has_many :populated_subcategories,     -> { order('name') }

Upvotes: 1

Related Questions