标签: reroute

Rails:如果条件重定向到页面

如果条件成立,我想重定向用户:

\n\n
class 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\n
class 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.

\n\n

如果我添加&& return,则该操作永远不会被调用。

\n

ruby-on-rails reroute conditional-statements

3
推荐指数
1
解决办法
1万
查看次数

Zend - 有条件地重新路由所有页面

如果条件通过,我希望能够将所有请求重新路由或重定向到我的网站到特定页面.我假设这必须在引导程序或调度程序的某个地方完成,但我不确定最好/最干净的方法是什么.

没有.htaccess重定向,因为需要在PHP中测试条件

这是我想要的:

if( $condition ) {
    // Redirect ALL Pages/Requests
}

// else, continue dispatch as normal...
Run Code Online (Sandbox Code Playgroud)

这里的想法是我们可以设置整个网站并将所有内容发送到启动页面,直到指定的日期/时间,此时它本身将"自动启动".

redirect zend-framework reroute

1
推荐指数
1
解决办法
990
查看次数