title: Rails country select dropdown for search: how to show priority countries at the top
body: <p>I want to perform a custom search and want to pass the country as one of the options to perform the search. My controller action for the search looks like this:</p>
  
  <pre><code>@articles = Article.filter(params.slice(:category, :country, :src_url, :date, :lang, :keywords, :title))
  .where(is_active: true)
  .paginate(:page =&gt; params[:page])
  </code></pre>
  
  <p>And my model contains all these scopes (example: scope :country, -> (country) { where country: country }</p>
  
  <p>So I've tried a few options, and so far didn't find one that I would be satisfied with completely.</p>
  
  <p><strong>Option 1:</strong> </p>
  
  <pre><code>&lt;%= select_tag :country, options_from_collection_for_select(ISO3166::Country.countries.sort_by(&amp;:name), 'name', 'name', params[:country]), :include_blank =&gt; true %&gt;
  </code></pre>
  
  <p><em>Pros:</em> Almost what I want - clean and short.</p>
  
  <p><em>Cons:</em> Can't figure out how is it working, really. I found it somewhere and modified a little using trial and error. But I didn't manage to find any documentation that would point on why and how it works, and with trial and error I can only go as far. From this comes the issue - I can't modify it to show particular countries on top of the list and rest sorted below.</p>
  
  <p><strong>Option 2:</strong></p>
  
  <pre><code>&lt;%= country_select(nil, :country, { priority_countries: %w(RU BR IN CN ZA), include_blank: true, selected: params[:country] }, {}) %&gt;
  </code></pre>
  
  <p><em>Pros:</em> It does exactly what I want with 1 exception.</p>
  
  <p><em>Cons:</em> It requires something called "user" as first argument, which I have set to as nil, and it leads to weird behavior in GET - it passes '%5Bcountry%5D=' instead of simply 'country=' and I don't like it. I didn't find a way to get rid of it or work around it.</p>
  
  <p>Any suggestions of how to do it better / cleaner?</p>