質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

0回答

1500閲覧

twitterログインでエラーが出ます。

Tomoaki_Fukuda

総合スコア75

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

0グッド

1クリップ

投稿2016/01/29 09:36

編集2016/01/29 14:26

###前提・実現したいこと
Ruby on Ralisにて、Twitterログイン機能を作成しております。

###発生している問題・エラーメッセージ
Twitterログインのボタンを押すと下記のメッセージが出るのですが、どのように対処するべきでしょうか?

###Config>routes.rb

ruby

1Rails.application.routes.draw do 2 3 #devise_for :users ,controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } 4 #resources :photos 5 root to: 'welcome#index' 6 get '/auth/:provider/callback' => 'sessions#create' 7 # get 'welcome/index' 8 9 # get 'welcome/index' 10 # The priority is based upon order of creation: first created -> highest priority. 11 # See how all your routes lay out with "rake routes". 12 13 # You can have the root of your site routed with "root" 14 # root 'welcome#index' 15 16 # Example of regular route: 17 # get 'products/:id' => 'catalog#view' 18 19 # Example of named route that can be invoked with purchase_url(id: product.id) 20 # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 21 22 # Example resource route (maps HTTP verbs to controller actions automatically): 23 # resources :products 24 25 # Example resource route with options: 26 # resources :products do 27 # member do 28 # get 'short' 29 # post 'toggle' 30 # end 31 # 32 # collection do 33 # get 'sold' 34 # end 35 # end 36 37 # Example resource route with sub-resources: 38 # resources :products do 39 # resources :comments, :sales 40 # resource :seller 41 # end 42 43 # Example resource route with more complex sub-resources: 44 # resources :products do 45 # resources :comments 46 # resources :sales do 47 # get 'recent', on: :collection 48 # end 49 # end 50 51 # Example resource route with concerns: 52 # concern :toggleable do 53 # post 'toggle' 54 # end 55 # resources :posts, concerns: :toggleable 56 # resources :photos, concerns: :toggleable 57 58 # Example resource route within a namespace: 59 # namespace :admin do 60 # # Directs /admin/products/* to Admin::ProductsController 61 # # (app/controllers/admin/products_controller.rb) 62 # resources :products 63 # end 64end 65

#app>users>sessions_controller.rb

ruby

1class SessionsController < ApplicationController 2 def create 3 user = User.find_or_create_from_auth_hash(request.env['omniauth.auth']) 4 session[:user_id] = user.id 5 redirect_to root_path, notice: 'ログインしました' 6 end 7end

#models>user.rb

ruby

1class User < ActiveRecord::Base 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :trackable, :validatable, :omniauthable 6 7 def self.find_or_create_from_auth_hash(auth_hash) 8 provider = auth_hash[:provider] 9 uid = auth_hash[:uid] 10 nickname = auth_hash[:info][:nickname] 11 image_url = auth_hash[:info][:image] 12 13 User.find_or_create_by(provider: provider, uid: uid) do |user| 14 user.nickname = nickname 15 user.image_url = image_url 16 end 17 end 18 end 19 20 21 22 23 24 25 #def self.find_or_create_from_oauth(auth) 26 # User.find_or_create_by(provider: auth.provider, uid: auth.uid) do |user| 27 # user.user_name = auth.info.nickname 28 # user.avatar_url = auth.info.image 29 # user.email = User.dummy_email(auth) 30 # user.password = Devise.friendly_token[0, 20] 31 # end 32 # end 33 34 # private 35 36 #def self.dummy_email(auth) 37 # "#{auth.uid}-#{auth.provider}@example.com" 38 #end 39

#db>migrate>20160125104011_devise_create_users.rb

ruby

1class DeviseCreateUsers < ActiveRecord::Migration 2 def change 3 create_table(:users) do |t| 4 ## Database authenticatable 5 t.string :email, null: false, default: "" 6 t.string :encrypted_password, null: false, default: "" 7 8 ## Recoverable 9 t.string :reset_password_token 10 t.datetime :reset_password_sent_at 11 12 ## Rememberable 13 t.datetime :remember_created_at 14 15 ## Trackable 16 t.integer :sign_in_count, default: 0, null: false 17 t.datetime :current_sign_in_at 18 t.datetime :last_sign_in_at 19 t.string :current_sign_in_ip 20 t.string :last_sign_in_ip 21 22 ## Confirmable 23 # t.string :confirmation_token 24 # t.datetime :confirmed_at 25 # t.datetime :confirmation_sent_at 26 # t.string :unconfirmed_email # Only if using reconfirmable 27 28 ## Lockable 29 # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 30 # t.string :unlock_token # Only if unlock strategy is :email or :both 31 # t.datetime :locked_at 32 33 34 t.timestamps null: false 35 end 36 37 add_index :users, :email, unique: true 38 add_index :users, :reset_password_token, unique: true 39 # add_index :users, :confirmation_token, unique: true 40 # add_index :users, :unlock_token, unique: true 41 end 42end 43

###エラーメッセージ
https://gyazo.com/dab4a8be573ad255867885176dc4716e

#23:30 エラーメッセージ変更
色々試していたら、エラーメッセージが変わって来ましたので、ご連絡致します。

どうぞお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問