我正在爲saas類創作任務2問題3。我完全是一名初學者,並且遇到問題。Rails鏈接到自定義操作失敗
分配要求你作列名「電影標題」的鏈接,其名字的電影排序
我在做什麼是使「電影標題」鏈接:
%th#title_header= link_to 'Movie Title', :controller => 'movies', :action => 'sort_by_title'
添加自定義操作movies_controller:
def sort_by_title
@movies = Movie.find(:all, :order => "title")
render movies_path
end
然後軌給我的錯誤:
No route matches {:controller=>"movies", :action=>"sort_by_title"}
然後我說OK,並把它添加到路由文件:
match '/movies?sort_by_title', :to => 'movies#sort_by_title'
現在索引頁面呈現正常,但當點擊鏈接MOVIE_TITLE什麼也沒有發生。
我在正確的道路上還是完全錯誤的?
耙路線打印:
movies GET /movies(.:format) {:action=>"index", :controller=>"movies"}
POST /movies(.:format) {:action=>"create", :controller=>"movies"}
new_movie GET /movies/new(.:format) {:action=>"new", :controller=>"movies"}
edit_movie GET /movies/:id/edit(.:format) {:action=>"edit", :controller=>"movies"}
movie GET /movies/:id(.:format) {:action=>"show", :controller=>"movies"}
PUT /movies/:id(.:format) {:action=>"update", :controller=>"movies"}
DELETE /movies/:id(.:format) {:action=>"destroy", :controller=>"movies"}
/movies?sort_by_title(.:format) {:controller=>"movies", :action=>"sort_by_title"}
謝謝
'rake routes'的輸出是什麼? – 2012-03-08 06:48:03
在問題中添加。 – alexZ 2012-03-08 07:17:00