【发布时间】:2012-07-02 22:37:58
【问题描述】:
几天来,我一直在与范围作斗争。我想为所有视图和控制器提供少量方法。 假设代码是:
def login_role
if current_user
return current_user.role
end
return nil
end
如果我将它包含在 application_helper.rb 中,那么它只对所有 View 可用,但对所有 Controller 不可用
如果我将它包含在 application_controller.rb 中,那么它对所有 Controller 都可用,但对所有 View 不可用。
【问题讨论】:
标签: ruby-on-rails scope