title: How to Sort Values in Rails Drop Down
body: <p>I have a dropdown with options_from_collection_for_select tag.I want to have the values in the dropdown list sorted by ascending order. (it's a list of cusromer names,just want them sorted by customer name in ascending order). This is what I have:</p>
  
  <pre><code>.row
   .col-md-3
     = label_tag "Customer/Supplier Name"
     = select_tag "search_customer_supplier[id]", options_from_collection_for_select(Organization.customers_and_suppliers, :id, :name, params.dig('search_customer_supplier', 'id')), class: "form-control parent_class chosen-select", id: "search_registered_customers", include_blank: true
  </code></pre>
  
  <p>In my model the customers_and_suppliers method difined as a scope. Here it is</p>
  
  <pre><code> scope :customers_and_suppliers, -&gt; { joins(accounts_dealer_types: :dealer_type).where(mst_dealer_types: {code: Organization::TYPES}) }
  
  </code></pre>
  
  <p>Finally i tried using this code </p>
  
  <pre><code>scope :customers_and_suppliers, -&gt; { joins(accounts_dealer_types: :dealer_type).where(mst_dealer_types: {code: Organization::TYPES}).order('name ASC') }
  
  </code></pre>
  
  <p>Then i got the results as ascending order.But in the dropdown there are so many duplicated records displaying,What will be the solution ?</p>