これは、コントローラーのメソッドです。
def sort
case params[:order_param]
when "title"
@cars = Movie.find(:all, :order => 'title')
when "rating"
@cars = Movie.find(:all, :order => 'rating')
else "release"
@cars = Movie.find(:all, :order => 'release_date')
end
redirect_to cars_path
end
これはビューです:
%th= link_to "Car Title", :action => 'sort', :order_param => 'title'
%th= link_to "Rating", :action => 'sort', :order_param => 'rating'
%th= link_to "Release Date", :action => 'sort', :order_param => 'release'
インデックス ページを開くと、次のエラー メッセージが表示されます。
No route matches {:action=>"sort", :order_param=>"title", :controller=>"cars"}
「rake routes」コマンドの結果
cars GET /cars(.:format) {:action=>"index", :controller=>"cars"}
POST /cars(.:format) {:action=>"create", :controller=>"cars"}
new_car GET /cars/new(.:format) {:action=>"new", :controller=>"cars"}
edit_car GET /cars/:id/edit(.:format) {:action=>"edit", :controller=>"cars"}
car GET /cars/:id(.:format) {:action=>"show", :controller=>"cars"}
PUT /cars/:id(.:format) {:action=>"update", :controller=>"cars"}
DELETE /cars/:id(.:format) {:action=>"destroy", :controller=>"cars"}