簡単な Ruby on Rails アプリケーションを作成しています。ユーザーはアプリケーションから facebook にログインでき、ログインに成功するとアプリケーションのホームページに戻ります。Rails キャストとhttp://blog.yangtheman.com/2012/02/09/facebook-connect-with-rails-omniauth-devise/に関するいくつかのチュートリアルに従いました。しかし、今はhttp 400 エラーが発生しています。gem omniauth 、 omniauth facebook 、および devise をインストールしました。親切に助けてください。同じビュー、モデル、およびコントローラーを投稿しています。私のアプリケーションには、すでに Twitter との統合が含まれています。
Index.html.erb (アプリケーションのホームページと言えます)
<h1>Twitter tatter</h1>
<form action="create" method="post">
<label for="keyword">Enter_keyword</label>
<input id="keyword" name="tweet[search]" size="30" type="text" />
<input type="submit" value="search" />
<%= link_to 'Login with Facebook', '/auth/facebook/' %>
<!--
<a href="/auth/facebook" class="auth_provider">
<%= image_tag "facebook_64.png", :size => "64x64", :alt => "Login_to_Facebook "%>Facebook
</a>
</br>
-->
</form>
</br></br></br></br></br>
<div id="container">
<% if (@tweets != nil && @tweets.count>0) then %>
User.rb (deviseで作成したモデル)
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
has_many :authentications # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me
end
認証モデル
class Authentication < ActiveRecord::Base
belongs_to :user
end
認証コントローラー
def create
auth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(auth['provider'], auth['uid'])
flash[:notice] = "Signed in successfully."
sign_in_and_redirect(:user, authentication.user)
end
Routes.rb
NewYearTweets::Application.routes.draw do
devise_for :users
resources :authentications
resources :tweetscontroller
get "tweets/index"
match 'tweets/create' => 'tweets#create'
match '/auth/:facebook/callback' => 'authentications#create
正常に動作しているため、Twitter 統合に関連するコードではなく、Facebook 統合に関連するコードを投稿しています。Facebookへのサインインに成功した後、インデックスページであるホームページにリダイレクトしたい