ruby on rails - Logout redirect error -
i having trouble logging user out , clearing sessions user. keep getting following error in rails server terminal window:
started delete "/logout" ::1 @ 2014-12-01 17:17:47 -0500 actioncontroller::routingerror (uninitialized constant sessoinscontroller):
here controller sessions:
class sessionscontroller < applicationcontroller # sessions not active record model def new end def create user = user.find_by(email: params[:session][:email].downcase) if user && user.authenticate(params[:session][:password]) log_in user redirect_to user else # flash.now used when going homepage danger # message not there anymore # designed displaying flash on rendered pages flash.now[:danger] = "invalid email/password combination" render 'new' end end # logs out current user, check session_helper details def destroy log_out redirect_to root_url, notice: "you have logged out." end end
here sessions helper: module sessionshelper
# logs in given user def log_in(user) session[:user_id] = user.id end # returns current logged-in user (if any) def current_user @current_user ||= user.find_by(id: session[:user_id]) end # returns true if user logged in, false otherwise def logged_in? !current_user.nil? end # logs out current user def log_out session.delete(:user_id) @current_user = nil end end
here routes.
get 'users/new' # these routes static_pages controller root 'static_pages#home' 'help' => 'static_pages#help' 'about' => 'static_pages#about' 'contact' => 'static_pages#contact' 'signup' => 'users#new' 'login' => 'sessions#new' post 'login' => 'sessions#create' delete 'logout' => 'sessoins#destroy' resources :users
can please help. thank in advance.
as can see routes
logout delete /logout(.:format) sessoins#destroy
sessions spelled wrong
just make sure line correct:
delete 'logout' => 'sessions#destroy'
Comments
Post a Comment