我试图在RoR中的each
对象/列表上调用ActiveRecord
,如下面的代码块所示。
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 :(得分:0)
导致错误的代码行是行42
。对where
的调用应该是:
Movie.where(:rating => rating_list.split(","))
"=>"
而非","