2012-08-09 44 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