所以我的 routes.rb 文件中有以下代码:
match "/movies/:id/find_similar_movies", :to => "movies#similar", :as => "find_similar_movies"
然后在一个haml页面中我有以下内容:
= link_to 'Find Movies With Same Director', find_similar_movies_path(:id=>@movie.id)
然后在我的控制器中我有:
def similar
movie=Movie.find_by_id([params(:id)])
@movie_title=movie.title
@similar_movies=Movie.find_all_by_director(movie.director)
end
在similar.html.haml中我写道:
%h2 Similar movies with #{@movie_title}
%ul
- @similar_movies.each do |movie|
%li = movie
= link_to 'Back to movie list', movies_path
当我按下= link_to 'Find Movies With Same Director', find_similar_movies_path(:id=>@movie.id)
我得到:
参数数量错误(1 代表 0)
Rails.root:/home/ubuntu/hw4_rottenpotatoes 应用程序跟踪 | 框架跟踪 | 全跟踪
app/controllers/movies_controller.rb:10:in `similar'
要求
参数:
{"id"=>"6"}
怎么了?谢谢你的时间...