我想將用戶重定向如果條件爲真:的Rails:重定向到頁面,如果條件
class ApplicationController < ActionController::Base
@offline = 'true'
redirect_to :root if @offline = 'true'
protect_from_forgery
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
,動作不會被調用。
我喜歡這種方法。我將如何重定向到'ApplicationController'中的一個函數?我對Rails完全陌生。 :) –
我可能是錯的,但你不能在ApplicationController中調用動作,對吧?我仍然收到錯誤。 –
@kevin你可以在應用程序控制器中調用redirect_to。你得到的錯誤是什麼? –