2011-01-29 38 views
3

如何配置我的Rails应用程序,以便在创建新用户的表单提交后(通过设计),我重定向到我自己想要的页面?在表单提交后设计覆盖重定向

谢谢

+1

提供的文档:https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-in – apneadiving 2011-01-30 00:18:55

回答

7

创建用户提交表单后创建的用户,然后登录所以你的页面将被重定向到实际上是登录页面后。如果你只是想改变这个页面,当用户创建,你可以在自定义登记控制器这样的设置session["#{resource_name}_return_to"]

class Users::RegistrationsController < Devise::RegistrationsController 
    def create 
    session["#{resource_name}_return_to"] = some_custom_path 
    super 
    end 
end 

您还可以在routes.rb中,这将重定向为您的用户对象根路径每当他们登录的所有用户:

match "user_root" => "users#home" 

最后,你可以在你的application_controller定义after_sign_in_path_for(resource_or_scope)方法,这将让你有条件地将用户重定向:

def after_sign_in_path_for(resource_or_scope) 
    if resource_or_scope.is_a?(User) 
    some_custom_path  
    else 
    super 
    end 
end 
请至少阅读3210