Using a framework I need 2 ActiveRecord scopes:
scope :tagged_with, lambda { |tag| {:conditions => [" tags like ? ", "% #{tag} %"] } }
scope :tagged_with_any, lambda { |tag_array | [HERE NEW IMPLEMENTATION] }
I want the second scope to be based on the first scope. If you would do it hard coded, you would do for a 2 element array:
lambda { | tag_array | tagged_with(tag_array[0]).tagged_with(tag_array[1]) }
which works, but how do I do it generic
lambda { | tag_array | tags.each { |t| tagged_with(t) } }
clearly doesn’t do the job.
Is this acceptable?
[edit] renamed to
tagged_with_allsince it’s what it really does. For atagged_with_any, Vanilla named scopes do not implement OR-concatenations; concatenating ORs conditions “manually” from scopes is doable but a bit messy. Note that you have libraries like Arel or Metawhere.