You should use something other than scope, since you really want to switch between the two cases (with or without the specified client ID) and respond differently. How about this:
class Product < ActiveRecord::Base def self.by_client(client) if client where(client_id: client) else all end end end
This code will always return something like scope output, so you can cling to it, etc.
Note that this also picks up code and does not require a specific area. And make sure you don't actually have has_many :clients for Product anyway ...
Peter source share