Grouped Collection Select Alphabetical Order Rails

前端 未结 5 1357
天命终不由人
天命终不由人 2021-01-03 05:27

I finally figured out how to implement Dynamic Select menus using this tutorial.

Everything works, But how does one organize the Cities in t

5条回答
  •  滥情空心
    2021-01-03 05:57

    How about using default_scope with ordering for City model?

    Or creating a State scope like that:

    scope :ordered_cities, ->{ cities.order(:name) }
    

    and than changing your select to

    f.grouped_collection_select :city_id, State.order(:name), :ordered_cities, :name, :id, :name, {:include_blank=> "Select a City"}, {:class=>'dropdown'}
    

提交回复
热议问题