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

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

问题描述

我有一个带有 Devise 的 Rails 3 项目,启用了可确认,因此用户必须在注册后通过电子邮件确认他们的帐户.目前,该项目将用户返回到登录页面并抛出您已成功注册..."通知.我想做的是将他们重定向到谢谢"页面,并附上进一步的说明(检查您的电子邮件、垃圾邮件文件夹等等).

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).

我的第一站是 Devise wiki,在那里我 找到此页面.看起来很容易,我做了以下改动,并完全按照指示...

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" }

我必须对方向进行的一项修改是将registrations"文件夹从/app/views/devise 视图文件夹中移到顶部/app/views 文件夹中,因为返回的错误是视图现在是失踪.无论如何,尽管控制器覆盖似乎有效(我认为否则这些视图最初不会被破坏),但这些说明不起作用......该页面忽略了 after_sign_up 并在注册后返回到登录页面.

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.

在互联网上打猎,包括其他 Stack Overflow 线程,但我没有发现任何对我有用的答案......因为 Devise 通常会在注册后自动登录,无需启用可确认).

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. 将 after_sign_up_path_for(resource) 移动到应用程序控制器中.不起作用.奇怪的是,对 after_sign_in_path_for(resource) 执行相同操作并以用户身份登录确实会重定向.

  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.

将 registrations_controller.rb 从/app/controllers/移动到/app/controllers/users 文件夹并相应地更新所有路由/引用/等.不行.

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

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

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.

我尝试了 def after_inactive_sign_up_path_for(resource),因为我认为可能是帐户尚未激活的事实是罪魁祸首.这也被忽略了.

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.

还值得一提的是,我曾尝试在这些重大更改后重新启动我的项目,但没有任何效果.

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?

推荐答案

您使用的是哪个版本的设计?我很确定这个问题最近已解决所以你可能需要来自 repo 的最新版本,它仍然是候选发布版本(尽管它应该很快就会发布,因为他们正在等待 omniauth 0.2 退出最近发生的测试版).

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).

我使用来自 github repo 的 Devise 1.2.rc2 和 rails 3.0.5.我将您提到的代码添加到我的自定义 RegistrationsController 中,并在创建新帐户后按预期转发给了 google.

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.

我的 RegistrationsController 的简化版本(在应用程序/控制器/用户中)

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

我的 routes.rb 条目

My routes.rb entry

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

来自我的 Gemfile

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天全站免登陆