2017-03-29 69 views
0

我想在ROR中的ActiveRecord對象/列表上調用each,如以下代碼塊所示。不受支持:在導軌上的黃瓜中的符號

41 Then /I should (not)?see movies with ratings: (.*)/ do |not_see, rating_li> 
42 @movies = Movie.where(:rating, rating_list.split(", ")) 
43 rating_list.split(",").map do |x| 
44  x.strip 
45 end.each do |rating| 
46  if not_see 
47  @movies.each do |movie| 
48   @movie.title 
49  end 
50  else 
51  puts "hello" 
52  end 
53 end 
54 end 

而這會產生以下錯誤消息:

And I should not see movies with ratings: G, PG-13, NC-17 # features/step_definitions/movie_steps.rb:41 
    unsupported: Symbol (RuntimeError) 
    ./features/step_definitions/movie_steps.rb:47:in `block (2 levels) in <top (required)>' 
    ./features/step_definitions/movie_steps.rb:45:in `each' 
    ./features/step_definitions/movie_steps.rb:45:in `/I should (not)?see movies with ratings: (.*)/' 
    features/filter_movie_list.feature:33:in `And I should not see movies with ratings: G, PG-13, NC-17' 

卸下線47在上面的代碼中擺脫了錯誤的。這是爲什麼?據我所知,所有這些都是有效的Ruby代碼。我錯過了什麼?

謝謝大家!

回答

0

導致錯誤的代碼行是42。到where調用應該是:

Movie.where(:rating => rating_list.split(",")) 

"=>"而不是","