Is it possible to have a scope with optional arguments?
activerecord, ruby-on-rails, ruby-on-rails-3, scope
Solution
Yes. Just use a `*` like you would in a method.
scope :print_args, lambda {|*args|
puts args
}
Problem
Is it possible to write a scope with optional arguments so that i can call the scope with and without arguments? Something like: ``` scope :with_optional_args, lambda { |arg| where("table.name = ?", arg) } Model.with_optional_args('foo') Model.with_optional_args ``` I can check in the lambda block if an arg is given (like described by Unixmonkey) but on calling the scope without an argument i got an `ArgumentError: wrong number of arguments (0 for 1)`