Rerouting custom routes when user is not authenticated (Devise, rails gem) -
i want reroute non-authenticated user login page, lets route http://localhost:3000/users/sign_in
aka devise/sessions#new
right default devise edit page when not logged in since built in. custom routes break app if you're not logged in since not apart of devise reroutes. how set these routes reroutes if not logged in? quoting directly devise below, i'm still @ loss on how implement routes, should code like?
goes inside lib
class customfailure < devise::failureapp def redirect_url new_user_session_url(:subdomain => 'secure') end # need override respond eliminate recall def respond if http_auth? http_auth else redirect end end end , add following in config/initializers/devise.rb: config.warden |manager| manager.failure_app = customfailure end
goes inside initializers
config.warden |manager| manager.failure_app = customfailure end
you can try in routes.rb
authenticated :user devise_scope :user root to: "dashboard#index" end end unauthenticated devise_scope :user root to: "homepage#index" end end
Comments
Post a Comment