如果条件成立,我想重定向用户:
\n\nclass ApplicationController < ActionController::Base\n @offline = 'true'\n redirect_to :root if @offline = 'true'\n protect_from_forgery\nend\n
Run Code Online (Sandbox Code Playgroud)\n\n编辑\n这就是我现在正在尝试的方法,但没有成功。默认控制器不是应用程序控制器。
\n\nclass ApplicationController < ActionController::Base\n before_filter :require_online \n\n def countdown\n\n end\n\nprivate\n def require_online\n redirect_to :countdown\n end\n\nend\n
Run Code Online (Sandbox Code Playgroud)\n\n这会导致浏览器错误Too many redirects occurred trying to open \xe2\x80\x9chttp://localhost:3000/countdown\xe2\x80\x9d. 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
,则该操作永远不会被调用。
如果条件通过,我希望能够将所有请求重新路由或重定向到我的网站到特定页面.我假设这必须在引导程序或调度程序的某个地方完成,但我不确定最好/最干净的方法是什么.
没有.htaccess重定向,因为需要在PHP中测试条件
这是我想要的:
if( $condition ) {
// Redirect ALL Pages/Requests
}
// else, continue dispatch as normal...
Run Code Online (Sandbox Code Playgroud)
这里的想法是我们可以设置整个网站并将所有内容发送到启动页面,直到指定的日期/时间,此时它本身将"自动启动".