title: pass a variable from view to controller in Ruby on Rails
body: <p>This is the method in the controller:</p>
  
  <pre><code>def sort
      case params[:order_param]
      when "title"  
      @cars = Movie.find(:all, :order =&gt; 'title')
      when "rating"
      @cars = Movie.find(:all, :order =&gt; 'rating')
  else "release"
      @cars = Movie.find(:all, :order =&gt; 'release_date')
  end
      redirect_to cars_path
  end
  </code></pre>
  
  <p>This is the view:</p>
  
  <pre><code>%th= link_to "Car Title", :action =&gt; 'sort', :order_param =&gt; 'title'
  %th= link_to "Rating", :action =&gt; 'sort', :order_param =&gt; 'rating'
  %th= link_to "Release Date", :action =&gt; 'sort', :order_param =&gt; 'release'
  </code></pre>
  
  <p>If I open the index page, this error message appears:</p>
  
  <pre><code>No route matches {:action=&gt;"sort", :order_param=&gt;"title", :controller=&gt;"cars"}
  </code></pre>
  
  <p>Result of the "rake routes" command</p>
  
  <pre><code>cars      GET    /cars(.:format)          {:action=&gt;"index", :controller=&gt;"cars"}
            POST   /cars(.:format)          {:action=&gt;"create", :controller=&gt;"cars"}
  new_car   GET    /cars/new(.:format)      {:action=&gt;"new", :controller=&gt;"cars"}
  edit_car  GET    /cars/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"cars"}
  car       GET    /cars/:id(.:format)      {:action=&gt;"show", :controller=&gt;"cars"}
        PUT    /cars/:id(.:format)      {:action=&gt;"update", :controller=&gt;"cars"}
        DELETE /cars/:id(.:format)      {:action=&gt;"destroy", :controller=&gt;"cars"}
  </code></pre>