###前提・実現したいこと
質問失礼いたします。twitterログインは完成し問題なく動いたのですが、さらに
Ruby on Railsでfacebookログイン機能を追加したいのですが、エラーが出てしまいます。
どうしたらこのエラーは消えるのでしょうか?
よろしくお願いします。
###発生している問題・エラーメッセージ
facebookログインボタンを押すとエラーメッセージ①
が出て、さらに「ok」を押すとエラーメッセージ②が出てしまいます。
###config>routes.rb
Rails.application.routes.draw do # devise_for :users root 'welcomes#index' get 'top' => 'topics#index' # get 'top' => 'topics#search' post 'top' => 'topics#create' get '/auth/:provider/callback' => 'sessions#twitter' get '/auth/:provider/callback' => 'sessions#facebook' end```
###vender>Gemfile
source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.4' # Use mysql as the database for Active Record gem 'mysql2', '0.3.18' # Use SCSS for stylesheets gem 'sass-rails', '~> 4.0.2' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.1.0' # See https://github.com/rails/execjs#readme for more supported runtimes gem 'therubyracer', platforms: :ruby # Use jquery as the JavaScript library gem 'jquery-rails' # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks gem 'turbolinks' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Unicorn as the app server # gem 'unicorn' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' end group :development do # Access an IRB console on exception pages or by using <%= console %> in views gem 'web-console', '~> 2.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'pry-rails' gem 'compass-rails','~> 2.0' gem 'sprockets', '2.11.0' gem 'kaminari' gem 'omniauth', '~> 1.2.1' gem 'omniauth-twitter', '~> 1.0.1' gem 'omniauth-facebook' gem 'ransack', '~> 1.2.2' end
###config>secrets.yml
# Be sure to restart your server when you modify this file. # Your secret key is used for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. # You can use `rake secret` to generate a secure secret key. # Make sure the secrets in this file are kept private # if you're sharing your code publicly. default_twitter: &default_twitter twitter_api_key: 'xxx' twitter_api_secret: 'xxx' default_facebook: &default_facebook facebook_api_key: 'xxx' facebook_api_secret: 'xxx' development: secret_key_base: xxxxxxxxxxxxx <<: *default_twitter <<: *default_facebook test: secret_key_base: xxxxxxxxxxxxxxx <<: *default_twitter <<: *default_facebook # Do not keep production secrets in the repository, # instead read values from the environment. production: secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> twitter_api_key: <%= ENV["TWITTER_CONSUMER_KEY"] %> twitter_api_secret: <%= ENV["TWITTER_CONSUMER_SECRET"] %> facebook_api_key: <%= ENV["FACEBOOK_API_KEY"] %> facebook_api_secret: <%= ENV["FACEBOOK_API_SECRET"] %>
###config>initializers>omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, Rails.application.secrets.twitter_api_key, Rails.application.secrets.twitter_api_secret provider :facebook, Rails.application.secrets.facebook_api_key, Rails.application.secrets.facebook_api_secret end
###db>migrate>20160218092058_create_users.rb
class CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :provider, null: false t.string :uid, null: false t.string :nickname, null: false t.string :image_url, null: false t.timestamps end add_index :users, [:provider, :uid], unique: true end end
###facebook開発者設定
facebook開発者設定(Basic)↓
https://gyazo.com/b7388eb81884663b756c6d925265ef5b
facebook開発者設定(Advanced)↓
https://gyazo.com/b1aa201f774e20ad258d096f1d99a42f
https://gyazo.com/6c05e5e1e23c643fbe331e34b7ec78f9
よろしくお願いいたします。
あなたの回答
tips
プレビュー