title: Rails 4 ActiveRecord Query: bind variables in order clause
body: <p>I'm attempting to have a dynamic order built into my mysql query so that certain matches are prioritized at the top.</p>
  
  <pre><code>Ticket.where(
    "id LIKE :search || name LIKE :search", 
    {search: "%#{params[:search]}]%"}
  ).order(
    "id = :exact DESC, name = :exact DESC, id LIKE :search DESC, name LIKE :search DESC", 
    {exact: params[:search], search: "%#{params[:search]}%"}
  )
  </code></pre>
  
  <p>The query should end up like this assuming params[:search] = 'search_value':</p>
  
  <pre><code>SELECT * FROM tickets
  WHERE id LIKE "%search_value%" || name LIKE "%search_value%"
  ORDER BY id = 'search_value' DESC, name = 'search_value' DESC, id LIKE "%search_value%" DESC, name LIKE "%search_value%" DESC;
  </code></pre>
  
  <p>Anytime I do this however I get an error from ActiveRecord::QueryMethods.validate_order_args saying Direction should be :asc or :desc.</p>
  
  <p>With the exception of manually sanitizing the search and then interpolating it directly into the order string, is there a way to get this to function like the where clause's bind variables?</p>