我想在条件为真时重定向用户:
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
这会导致浏览器出现错误:尝试打开“http://localhost:3000/countdown”时发生了太多重定向。如果您打开的页面被重定向到打开另一个页面,然后再次被重定向回原始页面,则可能会发生此情况。
如果我添加&& return
,则该操作将永远不会被调用。
ApplicationController
中的函数?我完全是 Rails 的新手。 :) - Kevin Brown&& return
。 - Kevin Brown:except => :countdown
。 - Kevin Brown