我們對Rails很陌生,希望使用我們主頁上的Javascript SDK「Connect with Facebook」按鈕。在我們的應用中使用此按鈕,我們希望允許用戶通過Facebook註冊我們的網站,並能夠將他們的Facebook個人資料圖片用作我們網絡應用的個人資料圖片。Rails 3應用程序 - 與Facebook連接的最佳方式
用我們的Rails 3應用程序實現這個Facebook連接的最佳方式是什麼?
devise_for :users
resources :authentications
resources :users do
member do
get :following, :followers
end
end
resources :sessions, :only => [:new, :create, :destroy]
resources :microposts, :only => [:create, :destroy]
resources :relationships, :only => [:create, :destroy]
match '/signup', :to => 'users#new'
match '/signin', :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy'
match '/contact', :to => 'pages#contact'
match '/home', :to => 'pages#home'
match '/help', :to => 'pages#help'
match '/feedback', :to => 'pages#feedback'
match '/privacy', :to => 'pages#privacy'
match '/terms', :to => 'pages#terms'
match '/', :to => 'pages#home'
resources :microposts
resources :users
resources :sessions, :only => [:new, :create, :destroy]
root :to => 'pages#home'
match "/auth/twitter/callback" => "sessions#omnicreate"
match "/auth/facebook/callback" => "sessions#omnicreate"
end
SessionsController
class SessionsController < ApplicationController
def new
@title = "Sign in"
end
def create
user = User.authenticate(params[:session][:email],
params[:session][:password])
if user.nil?
flash.now[:error] = "Invalid email/password combination."
@title = "Sign in"
render 'new'
else
sign_in user
redirect_back_or user
end
end
def destroy
sign_out
redirect_to root_path
end
end
感謝馬修我們跑了,並遇到了這個錯誤。我們收到了這個 'SessionsController#omnicreate'中的RecordInvalid' '驗證失敗:名稱不能爲空,電子郵件不能爲空,電子郵件無效,密碼太短(最少6個字符),密碼可能' t空白' – 2012-02-04 21:59:25
我要添加我們的'SessionsController'快速瀏覽一下,讓我們知道你在想什麼 – 2012-02-04 22:01:22
我的答案和評論的所有部分都是你需要填寫空白的地方。您需要解析'data'參數並使用結果將參數傳遞給'User.create!' – Matthew 2012-02-04 22:10:10