vendredi 13 mars 2015

Redirect root_path in rails for already signed_in user without using Devise

In my application i have root_path root 'home#mainPage' and though a user is signed in , he can accesss http://localhost:3000/ which i dont want. So i am following http://ift.tt/18j0qcZ answer to add this feature and i am getting undefined method user_signed_in? for AuthenticatedUser:Class. I am using Rails 4.2.0


My routes:



constraints(AuthenticatedUser) do
root :to => "users#show", as: :authenticated
end

root 'home#mainPage'


Lib/authenticated_user.rb:



class AuthenticatedUser
def self.matches?(request)
user_signed_in?
end
end


application_helper.rb



module ApplicationHelper
def user_signed_in?
!!session[:user_id]
end
def current_user
User.find(session[:user_id])
end
end


Config/application.rb



config.autoload_paths << Rails.root.join('lib')

Aucun commentaire:

Enregistrer un commentaire