{"id":1316,"date":"2022-08-30T15:15:31","date_gmt":"2022-08-30T15:15:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/devise-omniauth-undefined-method-new_session_path-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:31","modified_gmt":"2022-08-30T15:15:31","slug":"devise-omniauth-undefined-method-new_session_path-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/devise-omniauth-undefined-method-new_session_path-collection-of-common-programming-errors\/","title":{"rendered":"Devise + Omniauth = undefined method `new_session_path&#39;-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to implement a login system that only supports login through a Google Account to access Analytics data.<\/p>\n<p>I cannot get it working with the exception<\/p>\n<pre><code>undefined method `new_session_path' for #\n<\/code><\/pre>\n<p>I&#8217;m using <code>omniauth<\/code> with the <code>omniauth-google-oauth2<\/code> strategy.<\/p>\n<p>This is the Gemfile<\/p>\n<pre><code>source 'https:\/\/rubygems.org'\n\ngem 'rails', '3.2.3'\n\n# Bundle edge Rails instead:\n# gem 'rails', :git =&gt; 'git:\/\/github.com\/rails\/rails.git'\n\ngem 'mysql2'\ngem 'haml'\ngem 'haml-rails'\ngem 'omniauth'\ngem 'omniauth-google-oauth2'\ngem 'devise'\n\n# Gems used only for assets and not required\n# in production environments by default.\ngroup :assets do\n  gem 'sass-rails',   '~&gt; 3.2.3'\n  gem 'coffee-rails', '~&gt; 3.2.1'\n\n  # See https:\/\/github.com\/sstephenson\/execjs#readme for more supported runtimes\n  gem 'therubyracer', :platform =&gt; :ruby\n\n  gem 'uglifier', '&gt;= 1.0.3'\nend\n\ngem 'jquery-rails'\n\n# To use ActiveModel has_secure_password\n# gem 'bcrypt-ruby', '~&gt; 3.0.0'\n\n# To use Jbuilder templates for JSON\n# gem 'jbuilder'\n\n# Use unicorn as the app server\n# gem 'unicorn'\n\n# Deploy with Capistrano\n# gem 'capistrano'\n\n# To use debugger\n# gem 'ruby-debug19', :require =&gt; 'ruby-debug'\n\ngroup :test do\n  gem 'capybara'\n  gem 'database_cleaner'\n  gem 'rspec-rails'\n  gem 'cucumber-rails'\n  gem 'factory_girl_rails'\nend\n<\/code><\/pre>\n<p>This is the <code>config\/routes.rb<\/code><\/p>\n<pre><code>TestApp::Application.routes.draw do\n  devise_for :users, :controllers =&gt; { :omniauth_callbacks =&gt; \"users\/omniauth_callbacks\" }\n\n  devise_scope :user do\n    get 'sign_in', :to =&gt; 'users\/sessions#new', :as =&gt; :new_user_session\n    get 'sign_out', :to =&gt; 'users\/sessions#destroy', :as =&gt; :destroy_user_session\n  end\n\n  root :to =&gt; \"Landing#index\"\nend\n<\/code><\/pre>\n<p><code>app\/model\/user.rb<\/code>:<\/p>\n<pre><code>class User &lt; ActiveRecord::Base\n  # Include default devise modules. Others available are:\n  # :token_authenticatable, :confirmable,\n  # :lockable, :timeoutable and :omniauthable\n  # :database_authenticatable, :registerable\n  # :recoverable, :rememberable, :trackable, :validatable\n\n  devise :omniauthable\n\n  # Setup accessible (or protected) attributes for your model\n  # attr_accessible :email, :password, :password_confirmation, :remember_me\n  # attr_accessible :title, :body\nend\n<\/code><\/pre>\n<p><code>config\/intitializers\/omniauth.rb<\/code><\/p>\n<pre><code>Rails.application.config.middleware.use OmniAuth::Builder do\n  provider :google_oauth2, 'ID', 'SECRET', :scope =&gt; 'https:\/\/www.googleapis.com\/auth\/analytics.readonly'\nend\n<\/code><\/pre>\n<p><code>app\/controllers\/users\/omniauth_callback_controller.rb<\/code><\/p>\n<pre><code>class Users::OmniauthCallbacksController &lt; Devise::OmniauthCallbacksController\n  def google_oauth2\n    # You need to implement the method below in your model\n    @user = User.find_for_google_oauth2(request.env[\"omniauth.auth\"], current_user)\n\n    if @user.persisted?\n      flash[:notice] = I18n.t \"devise.omniauth_callbacks.success\", :kind =&gt; \"Google\"\n      sign_in_and_redirect @user, :event =&gt; :authentication\n    else\n      session[\"devise.google_data\"] = request.env[\"omniauth.auth\"]\n      redirect_to new_user_registration_url\n    end\n  end\nend\n<\/code><\/pre>\n<p>Can you please help me to understand what&#8217;s wrong here?<\/p>\n<p>P.S. this is the result I get running <code>rake routes<\/code><\/p>\n<pre><code>user_omniauth_callback    \/users\/auth\/:action\/callback(.:format)  users\/omniauth_callbacks#(?-mix:(?!))\nnew_user_session GET     \/sign_in(.:format)                      users\/sessions#new\ndestroy_user_session GET \/sign_out(.:format)                     users\/sessions#destroy\nroot                     \/                                       Landing#index\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:16:27. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to implement a login system that only supports login through a Google Account to access Analytics data. I cannot get it working with the exception undefined method `new_session_path&#8217; for # I&#8217;m using omniauth with the omniauth-google-oauth2 strategy. This is the Gemfile source &#8216;https:\/\/rubygems.org&#8217; gem &#8216;rails&#8217;, &#8216;3.2.3&#8217; # Bundle edge Rails instead: # gem [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[],"class_list":["post-1316","post","type-post","status-publish","format-standard","hentry","category-capybara","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1316"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1316\/revisions"}],"predecessor-version":[{"id":8757,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1316\/revisions\/8757"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}