How to use sort_by or order_by on view and controller with will_paginate?
<p>In my rails application I am limiting the amount of rooms displayed on a page through pagination, I want to allow the user to order/sort the results to different columns of the room model. I think I will need a drop down menu to do this, and then pass this data over to my rooms_controller maybe through an instance variable. </p>

<p><strong>How can I sort the rooms with the select tag according to a column and what do I need to do in the corresponding controller to make this work?</strong></p>

<p>At the moment I am using this for a drop down menu:</p>

<p><strong>index.html.erb</strong></p>

<pre><code>...
...
&lt;%= will_paginate @rooms %&gt;

&lt;div id="order-by"&gt;
     &lt;select&gt;
        &lt;option value="asc"&gt;Distance&lt;/option&gt;
        &lt;option value="asc"&gt;Name&lt;/option&gt;
        &lt;option value="asc"&gt;Price (low to high)&lt;/option&gt;
        &lt;option value="des"&gt;Price (high to low)&lt;/option&gt;
        &lt;option value="asc"&gt;Reviews&lt;/option&gt;
      &lt;/select&gt;
&lt;/div&gt;
</code></pre>

<p><strong>rooms_controller.rb</strong></p>

<pre><code>...
...
  def index
    @rooms = Room.paginate :page =&gt; params[:page], :per_page =&gt; 12
  end
...
</code></pre>

<p>My room model has listing_name:string, address: string, nightly_price:integer and has_many reviews. My review model belongs_to room. I am using geocoder gem for the location of an room.</p>

<p>I have searched allot and tried multiple things to make this work and I can not figure this one out. For any hints on how to solve this I would be really happy!
If you need further information just let me know.</p>