条件が真の場合にユーザーをリダイレクトしたい:
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
と、アクションが呼び出されることはありません。