如果条件为真,我想重定向用户:
class ApplicationController < ActionController::Base
@offline = 'true'
redirect_to :root if @offline = 'true'
protect_from_forgery
end
编辑 这是我现在正在尝试的,但没有成功。默认控制器不是应用程序控制器。
class ApplicationController < ActionController::Base
before_filter :require_online
def countdown
end
private
def require_online
redirect_to :countdown
end
end
这会导致浏览器错误Too many redirects occurred trying to open “http://localhost:3000/countdown”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.
如果我添加&& return
,则永远不会调用该操作。