Rails 3和Devise:重定向到页面以后注册(可确认) [英] Rails 3 and Devise: Redirecting to page following signup (confirmable)

查看:148
本文介绍了Rails 3和Devise:重定向到页面以后注册(可确认)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Rise 3项目与Devise,确认启用,所以用户必须通过电子邮件确认他们的帐户注册后。目前,该项目将用户返回到登录页面,并发出您已经注册成功通知。我想要做的是将其重定向到谢谢页面,并附上进一步的说明(检查您的电子邮件,垃圾邮件夹,blah blah)。



我的第一站是Devise wiki,其中我找到此页面。看起来很简单,我进行了以下更改,并按照正确的方向进行操作。



/app/controllers/registrations_controller.rb

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

/config/routes.rb

  devise_for:users,:controllers => {:registrations => 注册} 

我必须做的一个修改是移动注册文件夹在/ app / views / devise视图文件夹中,进入顶部/ app / views文件夹,因为返回的视图现在丢失了。无论如何,尽管控制器覆盖似乎正常工作(我不认为视图本来不会破坏),这些方向不起作用...页面忽略after_sign_up并在注册后返回到登录页面。



在互联网上狩猎,包括其他Stack Overflow线程,但没有找到对我有用的...或者回答困惑重定向注册登录,或者他们实际上在登录后正在改变重定向(因为Devise通常会在注册后自动登录,而无需启用确认)。



我尝试过的其他东西...


  1. 将after_sign_up_path_for(资源)移动到应用程序控制器中。不行奇怪的是,使用after_sign_in_path_for(资源)执行相同操作,并以用户身份登录重新导向。


  2. 将registration / controller / / app / controllers / users文件夹,并相应地更新所有路由/引用/ etc。不要去。


  3. 将Devise的registrations_controller.rb复制到我自己的registrations_controller.rb中。没有工作,只是抛出一个错误,我把它全部回来了。


  4. 我试过def after_inactive_sign_up_path_for(资源),因为我以为也许这个事实这个帐户还没有活跃,是罪魁祸首。这也是被忽略的。


  5. 还有一点值得一提的是,在这些重大变化之后,我已经尝试重新启动项目,但没有任何效果。


有没有人可以通过确认启用来取得成功?

解决方案

您使用哪种版本的设计?我很确定此问题最近已解决,因此您可能需要从repo的最新版本仍然是一个候选人(尽管它应该很快,因为他们正在等待omniauth 0.2离开最近发生的测试版)。



我正在使用Devise 1.2.rc2从github repo与rails 3.0.5。我添加了您提到的代码到我的自定义注册控制器,并在创建一个新帐户后转发到谷歌。



我的注册控制器的一个削减版本(在app / controllers / users)

  class Users :: RegistrationsController< Devise :: RegistrationsController 
protected
def after_sign_up_path_for(资源)
http://google.com
end

end

我的routes.rb条目

  devise_for:users,:controllers => {:registrations => 用户/注册} 

从我的宝石文件

  gem'devise',:git => git://github.com/plataformatec/devise.git

让我知道,在最新版本的设计中出现问题。


I have a Rails 3 project with Devise, confirmable enabled so the user has to confirm their account through email after registration. Currently the project returns the user to the login page and throws a "You've signed up successfully..." notice. What I want to do instead is redirect them to a "thank you" page, with further instructions (check your email, spam folder, blah blah).

My first stop was the Devise wiki, where I found this page. Looked easy enough, I made the following alterations and followed the directions exactly...

/app/controllers/registrations_controller.rb

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

/config/routes.rb

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

The one modification I had to make over the direction was moving the "registrations" folder out of the /app/views/devise view folder and into the top /app/views folder, as an error returned that the views were now missing. Anyway, despite the controller override appearing to work (I don't think the views would have originally broken otherwise), those directions do NOT work...the page ignores the after_sign_up and returns to the login page after signing up.

Went hunting on the internet including other Stack Overflow threads, but nothing I found has worked for me...either answers confuse redirecting sign up for sign IN, or what they're actually doing is changing the redirect after sign in (as Devise normally automatically signs in after registration without confirmable enabled).

Other things I have tried...

  1. Moving the after_sign_up_path_for(resource) into the application controller. Doesn't work. Oddly enough, doing the same with after_sign_in_path_for(resource) and signing in as a user DOES redirect.

  2. Moving the registrations_controller.rb from /app/controllers/ into /app/controllers/users folder and updating all routes/references/etc accordingly. No go.

  3. Copying Devise's registrations_controller.rb into my own registrations_controller.rb. Didn't work, just threw up an error and I rolled it all back.

  4. I tried def after_inactive_sign_up_path_for(resource), as I thought maybe the fact that the account wasn't active yet was the culprit. This is also ignored.

  5. It's also worth mentioning I have tried restarting my project after these major changes, but nothing takes.

Has anyone had any success with pulling this off with confirmable enabled?

解决方案

Which version of devise are you using? I'm pretty sure that this issue was recently resolved so you probably need the latest version from the repo which is still a release candidate (although it should be out soon as they were waiting for omniauth 0.2 to get out of beta which recently happened).

I am using Devise 1.2.rc2 from the github repo with rails 3.0.5. I added the code that you mentioned to my custom RegistrationsController and was forwarded to google as expected after creating a new account.

A cutdown version of my RegistrationsController (in app/controllers/users)

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

end

My routes.rb entry

devise_for :users, :controllers => { :registrations => "users/registrations" }

From my Gemfile

gem 'devise', :git => "git://github.com/plataformatec/devise.git"

Let me know if you're having problems on the latest version of devise.

这篇关于Rails 3和Devise:重定向到页面以后注册(可确认)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆