ruby on rails - Redirect to Index if user is not logged in -


i have in application_controller.rb:

private    def require_user_signed_in     unless user_signed_in?        # if user came page, can send them back.  otherwise, send       # them root path.       if request.env['http_referer']         fallback_redirect = :back       elsif defined?(root_path)         fallback_redirect = root_path       else         fallback_redirect = "/"       end        redirect_to fallback_redirect, flash: {error: "you must signed in view page."}     end   end 

and added in application.html.erb (the layout page) right after start of body:

<% require_user_signed_in %> 

my question is how why not working? getting undefined local variable or method error. not calling method correctly? have define somewhere usable in layout erb?

thank you.

add method application_helper.rb instead or make helper method, if want keep in application_controller.rb, remove private , add following line

helper_method :require_user_signed_in 

hope helps!


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -