ruby on rails - Authentication w/ Omniauth (No Devise) - How to Check is Signed In in Routes? -


i'm using omniauth-oauth2 authentication (no devise). define different roots users signed in , not, include secure dashboard. have current_user method in application controller, can't seem access in routes. have recommendations how can best this?

application controller:

helper_method :current_user  private      def current_user         @current_user ||= user.find(session[:user_id]) if session[:user_id]     end 

this not work:

blog::application.routes.draw    if :current_user    root :to => "home#show"  else    root :to => "home#index"  end  end 

in routes.rb file, specify constraint routing based on condition.

root :to => 'home#show', :constraints => lambda{|req| !req.session[:user_id].blank?} root :to => 'home#index' 

hope useful storing user_id in session, work


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -