我是这样说的。 我不敢肯定的是,随着更新的“Devise”的改变,昨天在“Devise:邮局”的制作中做了很多工作。 (见code和ticket ,以供参考)。
基本上,它 b倒了无法在邮件地址查阅<代码>session。 因此,你必须把这一方向作为变量。 浏览器使用<代码>以下关于贵用资源的方法(User<>/code>,就我而言),然后发送确认电子邮件。 这意味着,我只能把会议直接通过给邮寄人。 因此,我感到,这只是为了取得这一功能而进行的初步工作,但在这里是:
查阅<代码>redirect_to 用户必须增加一个变量,从而:
class User < ActiveRecord::Base
…
attr_accessor :return_to
…
end
然后,当你首次创建用户时,你必须确定这一变量。
我已经为登记设立了一个海关控制员。 (见Devise Readme, 说明如何建立这一系统,或见@ramc关于方向的答复)。 但是,完成这一部分相对容易,我只是把它添加到参数上,让其他人自己照顾。
class RegistrationsController < Devise::RegistrationsController
def create
params[:user][:return_to] = session[:user_return_to] if session[:user_return_to]
…
super
end
end
现在,用户有一套可变的<代码>return_to,现列出。 我们只需要查阅<代码>确认_instructions email。 我已经重新撰写了确认部分内容——内容结构。
<% if @resource.return_to %>
<%= link_to Confirm my account , confirmation_url(@resource, :confirmation_token => @resource.confirmation_token, :redirect_to => @resource.return_to) %>
<% else %>
<%= link_to Confirm my account , confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>
<% end %>
(对于新加入者而言,@resource
是用于界定用户的可变幻用途。)
现在,一旦用户点击这一环节,我们就需要重新定位。 @ramc s 在
之前很好地完成了这项工作:
class ConfirmationsController < Devise::ConfirmationsController
before_filter :set_redirect_location, :only => :show
def set_redirect_location
session[:user_return_to] = params[:redirect_to] if params[:redirect_to]
end
end
这将考虑到这样的情况,即新用户进入受保护的网页,然后打上标识,点击确认链接,并适当改用受保护的网页。
现在,我们只是需要关注用户做上述事情的情况,而不是点击这一联系,而是试图回到受保护的网页上。 在这种情况下,要求他们签署/签署。 他们签了字,然后被要求确认其电子邮件,并有权选择转拨确认书的电子邮件。 这些文件载于其电子邮件,我们现在需要将redirect_to
变量列入新的确认书电子邮件。
为了做到这一点,我们需要修改主计长,就像我们如何做登记主计长那样。 现在我们需要修改<代码>create方法。 该盒子的出路是,在用户上使用一个称为send_confirmation_instructions
的类别方法。 我们希望重新制定这一方法,以便我们能够通过return_to
。 可变。
class ConfirmationsController < Devise::ConfirmationsController
def create
self.resource = resource_class.send_confirmation_instructions(params[resource_name],session[:user_return_to])
if resource.errors.empty?
set_flash_message(:notice, :send_instructions) if is_navigational_format?
respond_with resource, :location => after_resending_confirmation_instructions_path_for(resource_name)
else
respond_with_navigational(resource){ render_with_scope :new }
end
end
end
与Devise相比,唯一不同的是,第1行<代码>create,我们在其中通过两个变量。 现在我们需要重新制定这一方法:
class User < ActiveRecord::Base
def self.send_confirmation_instructions(attributes={},redirect=nil)
confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
confirmable.return_to = redirect if confirmable.persisted?
confirmable.resend_confirmation_token if confirmable.persisted?
confirmable
end
end
confirmable
becomes an instance of User (the current user based on email). So we just need to set return_to
.
这就是说。