我試圖根據由ActionController before_filter確定的某些條件來設置默認範圍。在控制器:根據某些條件設置default_scope
before_filter :authorize
...
def authorize
if some_condition
@default_scope_conditions = something
elsif another_condition
@default_scope_conditions = something_else
end
end
裏面的ActiveRecord的
default_scope :conditions => @default_scope_conditions
但它似乎沒有工作,在過濾器之前被調用,但default_scope不被設置。你能否告訴我我做錯了什麼,如何解決這個問題,或者建議我採取其他方式來實現這一目標。
你設置@default_scope_conditions - 這是一個實例變量從** **控制器和你期望從**模型**中讀取它。除非作爲方法參數傳遞,否則從模型中不可見。 – 2010-04-17 10:00:43