Question

I have the following named scope:

named_scope :find_all_that_match_tag, lambda { |tags| {
            :select => "articles.id, tags.name",
            :joins => :tags,
            :conditions => ["tags.name IN (?)",tags]}
          }

It works fine like this in script/console

Article.find_all_that_match_tag(["cooking"])

But if i use it like this, as part of an anonymous scope

scope = Article.scoped({})
scope = scope.scoped.find_all_that_match_tag(["cooking"])

i get a warning, on the second line:

/Users/Server/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:13: warning: multiple values for a block parameter (0 for 1)
from /Users/Server/.gem/ruby/1.8/gems/activerecord-2.3.4/lib/active_record/named_scope.rb:92

It still works, but whats causing the warning? and how do i get rid of it please?

Was it helpful?

Solution

First of all I would probably not bother including an anonymous scope without conditions.

That said, I think the warning is in the call to scoped as part of the chain with no argument. It shouldn't be necessary, you have a named scope "find_all_that_match" that you should be able to simply chain to any previous scopes, anonymous or named.

scope = Article.scoped({})
scope.find_all_that_match_tag(["cooking"])

Might also be worth using a shorter named scope like "tagged_as" or simply "tagged"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top