Christian Fazzini
Christian Fazzini

Reputation: 19713

Devise returning NoMethodError (undefined method `new_user_session_path'

I just upgraded to Devise 2.0 from Devise 1.5.1.

Using omniauth (1.0.3) 
Using omniauth-oauth (1.0.1) 
Using omniauth-twitter (0.0.8) 

I'm using this for twitter authentication. I keep getting:

NoMethodError (undefined method `new_user_session_path' for #<ActionDispatch::Routing::RoutesProxy:0x00000009b57c10>

My routes look like:

  devise_for :users, :controllers => { :sessions => 'sessions', :omniauth_callbacks => 'authentications' }, :skip => [:sessions] do
    get 'sign-out' => 'sessions#destroy', :as => :destroy_user_session
  end

This error shows up in production. Everything works on development. I am also running on Heroku, if that makes a difference.

Upvotes: 3

Views: 9439

Answers (2)

zsquare
zsquare

Reputation: 10146

You've added session to skip, which means devise wont create those routes. If you want to customise your urls, follow the documentation here.

In your case, it would be

devise_for :users, :skip => [:sessions]
as :user do
  get 'sign-in' => 'devise/sessions#new', :as => :new_user_session
  post 'sign-in' => 'devise/sessions#create', :as => :user_session
  delete 'sign-out' => 'devise/sessions#destroy', :as => :destroy_user_session
end

Upvotes: 3

Uchenna
Uchenna

Reputation: 4089

I also had a similar problem so i created a custom rout and it worked for me

match '/users/sign_in' => "devise/sessions#create", :as => :create_user_session

I hope this works for you. You can customise it to suit your need

Upvotes: 1

Related Questions