twitterログインでエラーが出ます。
前提・実現したいこと
Ruby on Ralisにて、Twitterログイン機能を作成しております。
発生している問題・エラーメッセージ
Twitterログインのボタンを押すと下記のメッセージが出るのですが、どのように対処するべきでしょうか?
Config>routes.rb
Rails.application.routes.draw do
#devise_for :users ,controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
#resources :photos
root to: 'welcome#index'
get '/auth/:provider/callback' => 'sessions#create'
end
app>users>sessions_controller.rb
class SessionsController < ApplicationController
def create
user = User.find_or_create_from_auth_hash(request.env['omniauth.auth'])
session[:user_id] = user.id
redirect_to root_path, notice: 'ログインしました'
end
end
models>user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :omniauthable
def self.find_or_create_from_auth_hash(auth_hash)
provider = auth_hash[:provider]
uid = auth_hash[:uid]
nickname = auth_hash[:info][:nickname]
image_url = auth_hash[:info][:image]
User.find_or_create_by(provider: provider, uid: uid) do |user|
user.nickname = nickname
user.image_url = image_url
end
end
end
#def self.find_or_create_from_oauth(auth)
# User.find_or_create_by(provider: auth.provider, uid: auth.uid) do |user|
# user.user_name = auth.info.nickname
# user.avatar_url = auth.info.image
# user.email = User.dummy_email(auth)
# user.password = Devise.friendly_token[0, 20]
# end
# end
# private
#def self.dummy_email(auth)
# "#{auth.uid}-#{auth.provider}@example.com"
#end
db>migrate>20160125104011_devise_create_users.rb
class DeviseCreateUsers < ActiveRecord::Migration
def change
create_table(:users) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :users, :email, unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token, unique: true
# add_index :users, :unlock_token, unique: true
end
end
エラーメッセージ
https://gyazo.com/7aef0936833cd405feafcc16a2dc2b26
どうぞお願い致します。