- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我在 Rails 2 中工作,我有一个模型级方法,我想在 before_filter 中调用它。我怎样才能做到这一点?我试过这种方法,但它不起作用
before_filter :LmsUser.can_edit_update, :only => [:new, :create, :edit, :update, :destroy]
最佳答案
您应该向您的 Controller 添加一个方法并将其用作之前的过滤器。例如:
class MyController < ApplicationController
before_filter :check_permissions,
:only => [:new, :create, :edit, :update, :destroy]
private
def check_permissions
unless LmsUser.can_edit_update
# redirect_to, render, or raise
end
end
end
参见 filters section of the Action Controller Overview guide获取更多信息。
关于ruby-on-rails - 在 before_filter 中调用的模型级方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12889581/
有一个 gem,它附加一个 before_filter 到 Rails 应用: class Railtie [ [0] :set_locale, [1] :set_language_
如何测试当访问 Controller 中的一个 Action 时,该 Controller 的 before_filter 将被执行? before_filter 在单独的示例组中进行测试,因此无需为
在允许用户编辑员工信息之前,我需要确保他们拥有正确的权限。具体来说,用户必须是管理员,并且用户必须与员工属于同一家公司。执行此类操作的最佳方法是什么? def EmployeesController
我正在使用 Devise 的内置 before_filter :authenticate_user! .如果用户未通过 before 过滤器(尝试在注销时执行操作),我想在我的应用程序助手中调用我自己
我有许多资源(行程、时间表等),其操作应该仅限于资源的所有者。 您如何使用 ApplicationController 中定义的 #require_owner 方法实现代码以实现此目的?理想情况下,代
我在最近从 1.9(?) 升级到 2.3.11 的 Rails 应用程序中使用过滤器之前遇到问题。为了尝试调试它,我在 Controller 中放置了一个 before_filter: before_
我想用 rspec 指定我的 Controller before_filter。我想为此使用 ActionController::Testing::ClassMethods#before_filter
是否有可能: before_filter :authenticate_user! || :authenticate_admin! 最佳答案 before_filter :do_authenticati
我有一个方法可以做这样的事情: before_filter :authenticate_rights, :only => [:show] def authenticate_rights proje
这个问题在这里已经有了答案: before_filter with parameters (5 个回答) 关闭8年前。 在我的application_contorller我有方法: def autho
没有很多具体的代码,这只是模糊的,但我会提供我能提供的。 给定一个 rails 引擎,一个基本引擎而不是在其自己的空间中的可安装引擎,我如何使引擎中的方法作为应用程序 Controller 的 bef
我有一个组资源,我正在尝试使用适当的授权进行设置。 我试图实现的授权逻辑是这样的: 只有群组成员才能查看他们的群组。 管理员可以查看任何组,以及执行其他操作。 我正在尝试使用组 Controller
我知道 before_filter 仅适用于 Rails 中的 Controller ,但我想要一个模型这样的东西:每当我的模型中的一个方法被调用时,我想运行一个方法来确定被调用的方法是否应该运行。从
我想在 Controller 中定义一个 before_filter,但总是让它最后执行。 我知道 append_before_filter,但我想在一个模块中指定这个过滤器,其他类也可能稍后添加其他
rails 是否对使用以下任一用法的 before 过滤器的执行顺序做出任何保证: before_filter [:fn1, :fn2] 或 before_filter :fn1 before_fil
是否可以使用 OmniAuth 在某些操作之前要求登录? 我记得在 Railscast 中,Devise 有一个 before_filter,但是 OmniAuth 有吗? 最佳答案 您可以添加bef
我有一些之前的过滤器,用于在逐个资源级别上控制对资源的访问。基本思路如下: 用户可以是 user 或 admin,并且可以访问基于“accesses”表的特定资源。 资源/方法的访问权限可以限制为 a
所以我有 ApplicationController.rb: class ApplicationController 为什么不继承该方法,以便将其正确用作 before_filter? 最佳答案 c
当我向我的 ruby Controller 发送 ajax 请求时,before_filter 函数似乎为每个 ajax 请求调用了两次。我使用 before_filter 进行身份验证。 我使用
我在 Rails 2 中工作,我有一个模型级方法,我想在 before_filter 中调用它。我怎样才能做到这一点?我试过这种方法,但它不起作用 before_filter :LmsUser.can
我是一名优秀的程序员,十分优秀!