Rails: Redirect to page if condition -


i want redirect user if condition true:

class applicationcontroller < actioncontroller::base   @offline = 'true'   redirect_to :root if @offline = 'true'   protect_from_forgery end 

edit i'm trying no success. default controller not application controller.

class applicationcontroller < actioncontroller::base     before_filter :require_online       def countdown      end  private   def require_online     redirect_to :countdown   end  end 

this gives browser error too many redirects occurred trying open “http://localhost:3000/countdown”. might occur if open page redirected open page redirected open original page.

if add && return, action never gets called.

in addition jed's answer

need comparison operator, not assignment operator:

 redirect_to :root if @offline == 'true' 

if you're having further difficulties, simplify tests with:

 redirect_to(:root) if @offline == 'true' 

or maybe should true boolean , not string?

 redirect_to :root if @offline 

class applicationcontroller < actioncontroller::base    before_filter :require_online    private     def require_online        redirect_to(:root) && return if @offline == 'true'     end  end 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -