2012-08-09 45 views
2

我想創建我的網站用戶註冊視圖和模型,但我有一個小問題:設計和Facebook定製路由

我使用的設計和omniauth得到了Facebook Connect功能工作,它的工作原理, 但我希望我的臉書用戶在第一次登錄時創建自己的密碼, 這也行得通,我將他們重定向到填寫的註冊表單,他們只需輸入密碼。但我希望他們去第二個名爲/views/registrations/new_facebook.html.erb的「sign_up表單」,他們只能輸入他們的密碼,我還會添加一些其他信息,

我創建了正確的視圖,測試,但我不知道如何建立正確的路線繞過制定默認

match '/facebook' => 'registrations#new', :as => 'new_facebook_user_registration' 

我相信這個問題是比賽,因爲這是不是認可,

如果有人可以幫助我,將是巨大的謝謝,

我說我的控制器代碼omniauth:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 
def all 
user = User.from_omniauth(request.env["omniauth.auth"]) 
if user.persisted? 
     flash[:success] = "Welcome back" 
      sign_in_and_redirect user 
else 
    session["devise.user_attributes"] = user.attributes 
    redirect_to new_facebook_user_registration_url 
end 
end 
alias_method :facebook, :all 

我怎樣才能讓redirect_to的new_facebook_user_registration_url實際工作?

回答

1
devise_scope :user do 
match "registrations/new_facebook" => "registrations#new_facebook" 
end 

這就是我在註冊複製的解決方案控制器新方法,並命名爲new_facebook,現在一切都按預期工作!

0

我認爲問題在於你不重寫重定向到該路徑的設計方法。另外根據設計文檔,您的路線應該設置爲「devise_for」呼叫。

下面是描述如何做你要求做的維基頁面,雖然你可能需要一些自定義邏輯來處理不是Facebook註冊的情況。

https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration

從該頁面中的一些示例代碼:

class RegistrationsController < Devise::RegistrationsController 
    protected 

    def after_sign_up_path_for(resource) 
    '/an/example/path' 
    end 
end 

和一個路線:

devise_for :users, :controllers => { :registrations => "registrations" } 
+0

在OmniauthCallbacksController中,我怎麼能重定向到比new_user_registration_url其他東西比如說new_facebook_registration_url?我想在控制器的一種情況下使用重定向是可能的嗎? – 2012-08-09 13:20:56