28

I am using Rails + Devise + OmniAuth + Google OAuth2.

My user model (user.rb) contains:

devise :registerable, :omniauthable, :omniauth_providers => [:google_oauth2]

My routes.rb look like:

Rails.application.routes.draw do
  devise_for :users, controllers: { omniauth_callbacks: 'omniauth_callbacks' }
  devise_scope :user do
      get 'sign_in', :to => 'devise/sessions#new', :as => :new_user_session
      post 'sign_in', :to => 'devise/session#create', :as => :user_session
      get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_user_session
  end

  get 'services', to: 'static_pages#services'
  get 'my_account', to: 'my_account#index'
  get 'invite', to: 'invite#show'
  get 'invite/:id', to: 'invite#show'

  root 'static_pages#home'
end

When I go to /sign_in, I get an exception like:

undefined method `session_path' for #<#<Class:0x007f9b7173af28>:0x007f9b713d8da8>

in:

~/.rvm/gems/ruby-2.1.1/gems/devise-3.2.4/app/views/devise/sessions/new.html.erb

in line:

<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>

If I add :database_authenticatable to user.rb it all starts working, but I want my users to be able to sign-in through Google OAuth2 only, so I don't want :database_authenticable. It looks like session_path is not available for some reason, but I am not sure why and how to make it available.

Thanks, Jen

user3777406
  • 281
  • 1
  • 3
  • 3
  • 1
    I have the same problem, but I am not using OmniAuth either Google OAuth2. Did you solve it at the end? – Moh Jun 26 '15 at 10:38

3 Answers3

80

You need to reboot the rails server. That was the solution for me.

Abel
  • 3,989
  • 32
  • 31
  • 2
    Yes. I added a registrations_controller.rb file and forgot to reboot. Lesson: the file structure is like an initializer in development mode. – Jerome Aug 31 '16 at 10:59
  • 6
    Useful answer. Saved more time than Geico saves on insurance. – GavinBelson Mar 02 '18 at 18:09
1

I do believe that, as you use devise_scope for the sessions paths, you need to add skip to your devise_for call, like so:

devise_for :users, skip: [:sessions], controllers: { omniauth_callbacks: 'omniauth_callbacks' }

Doing so will not generate the route helpers for the sessions controller

Benjamin Bouchet
  • 12,971
  • 2
  • 41
  • 73
0

If you add or modify anything in the devise configuration, you need to reboot the rails server. just stop and run the rails server command again

Syamlal
  • 714
  • 1
  • 11
  • 20