So I have the following code in my routes.rb file:
match "/movies/:id/find_similar_movies", :to => "movies#similar", :as => "find_similar_movies"
then in a haml page I have the following:
= link_to 'Find Movies With Same Director', find_similar_movies_path(:id=>@movie.id)
then in my controller I have:
def similar
movie=Movie.find_by_id([params(:id)])
@movie_title=movie.title
@similar_movies=Movie.find_all_by_director(movie.director)
end
and in the similar.html.haml I write:
%h2 Similar movies with #{@movie_title}
%ul
- @similar_movies.each do |movie|
%li = movie
= link_to 'Back to movie list', movies_path
when I press the = link_to 'Find Movies With Same Director', find_similar_movies_path(:id=>@movie.id)
I get:
wrong number of arguments (1 for 0)
Rails.root: /home/ubuntu/hw4_rottenpotatoes Application Trace | Framework Trace | Full Trace
app/controllers/movies_controller.rb:10:in `similar'
Request
Parameters:
{"id"=>"6"}
What's wrong?Thanks for your time...
params(:id)
is trying to call a method called params
with an :id
argument, which is not how this works. params
should be treated like a hash, the lookup syntax for which is params[:id]
.
Try Movie.find_by_id(params[:id])
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.