Group could be sorted alphabetically, but I can't rearrange the labels in alphabetical order.
Each user can post their fashion style from Fashion form(fashions/new). Fashion forms are not just underwear, there are various things such as jeans and sandals. For example, when a user selects underwear, the user selects a product name from the underwear's drop box menu classified by brand.
For now, drop box looks like
Adidas
adidas 5
adidas 3
adidas 1
Nike
Nike 3
Nike 1
Nike 2
want to look like
Adidas
adidas 1
adidas 2
adidas 3
Nike
Nike 1
Nike 2
Nike 3
There are four tables including an intermediate table.
### Fashion model
has_one :fashion_underwear
accepts_nested_attributes_for :fashion_underwear
### FashionUnderwear model(Intermediate table)
belongs_to :fashion
belongs_to :underwear
### Underwear model
has_many :fashion_underwears
belongs_to :brand
### Brand model
has_many :underwear
### Fashions.controller
def new
@fashion = Fashion.new
@fashion.build_fashion_underwear
@brand = Brand.includes(:fashion_underwears).joins(:fashion_underwears).order(brand_name: :asc)
end
### Fashion/new.html
= simple_form_for(@fashion) do |f|
= f.simple_fields_for :fashion_underwear do |p|
= p.input :underwear_id, collection: @brand, as: :grouped_select, group_method: :underwears, group_label_method: :brand_name, label_method: :underwear_name
I studied various things and tried it, but it did not go well.
Thank you for your support!