RoR:使用设计和cancan注册后重定向用户

时间:2013-07-19 04:41:57

标签: ruby-on-rails devise ruby-on-rails-3.2 cancan

我已经设计并且可以设置,我在注册后无法将用户重定向到某个页面。

class RegistrationsController < Devise::RegistrationsController
  def after_sign_up_path_for(resource)
    "http://google.com"
  end
end

然后在我的路线中:

  authenticated :user do
    root :to => "dashboard#show"
  end

现在,当我注册用户时,它只会被定向到仪表板#show。我试图让它去google.com,但它并没有。难道我做错了什么?或者在使用CanCan注册后还有另一种方法可以重定向用户吗?

由于

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

答案 2 :(得分:0)

您添加到application_controller.rb

 def after_sign_up_path_for(resource)
   "http://google.com"
 end

来源:redirec_to external_url

或者您可以在路线上使用某些外部链接,如

# in `config/routes.rb` :

match "/google" => redirect("http://google.com"), :as => :google

# in `registrations_controller.rb` :

def after_sign_up_path_for(resource)
   google_path
end 

如果您使用的是Devise的确认(用户注册后未激活),您可以使用after_inactive_sign_up_path_for方法。

# controllers/registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController


  def after_inactive_sign_up_path_for(resource)
    "http://google.com"
  end

end