Setting default_scope according to some criteria
Posted
by Tam
on Stack Overflow
See other posts from Stack Overflow
or by Tam
Published on 2010-04-17T09:35:04Z
Indexed on
2010/04/17
9:43 UTC
Read the original article
Hit count: 261
ruby-on-rails
|default-scope
I'm trying to set default scope according to some criteria determined by ana ActionController before_filter. In controller:
before_filter :authorize
...
def authorize
if some_condition
@default_scope_conditions = something
elsif another_condition
@default_scope_conditions = something_else
end
end
Inside the ActiveRecord
default_scope :conditions => @default_scope_conditions
But it doesn't seem to work, the before filter gets called but the default_scope doesn't get set. Could you please advise me what I'm doing wrong and how to fix it or suggest me some other way of achieving that.
© Stack Overflow or respective owner