ruby-on-rails – 应用程序控制器中的before_filter,仅用于获取
发布时间:2020-12-17 03:37:16 所属栏目:百科 来源:网络整理
导读:我需要在我的ApplicationController中设置一个before_filter,如果用户尚未同意新的服务条款,则会重定向用户.但是,我想将过滤器限制为仅根据请求类型运行. 我想写这样的东西: class ApplicationControllerbefore_filter :filter,:only = {:method = :get} 这
我需要在我的ApplicationController中设置一个before_filter,如果用户尚未同意新的服务条款,则会重定向用户.但是,我想将过滤器限制为仅根据请求类型运行.
我想写这样的东西: class ApplicationController before_filter :filter,:only => {:method => :get} 这样的事情可能吗? 解决方法before_filter :do_if_get private def do_if_get return unless request.get? # your GET only stuff here. end 或者更简单 before_filter :get_filter,if: Proc.new {|c| request.get? } private def get_filter # your GET only stuff here. end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |