激活用户时使用acts_as_state_machine的restful_authentication中的DoubleRenderError
在使用 restful_authentication
与 acts_as_state_machine
和电子邮件激活的项目中,每当用户通过电子邮件链接执行激活操作时,我都会收到双重渲染错误。
我使用默认值
def activate
self.current_user = params[:activation_code].blank? ? false : User.find_by_activation_code(params[:activation_code])
if logged_in? && !current_user.active?
current_user.activate!
flash[:notice] = "Signup complete!"
end
redirect_back_or_default('/')
end
来激活,并使用默认值
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
来重定向。 重定向方法在所有其他情况下都以相同的方式调用。
双重渲染错误发生在以“/”路由的页面 main_page/home 的渲染处。
我应该寻找什么?
In a project which uses restful_authentication
with acts_as_state_machine
and email activation, I get a double render error whenever a user does the activation action from the email link.
I'm using the default
def activate
self.current_user = params[:activation_code].blank? ? false : User.find_by_activation_code(params[:activation_code])
if logged_in? && !current_user.active?
current_user.activate!
flash[:notice] = "Signup complete!"
end
redirect_back_or_default('/')
end
to activate, and the default
def redirect_back_or_default(default)
redirect_to(session[:return_to] || default)
session[:return_to] = nil
end
to redirect. The redirect method works in every other case it's called in the same way.
The double render error occurs at the render of the page main_page/home that is routed as "/".
What should I be looking for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为状态机有时会出现一些奇怪的行为,其中写入数据库的保存记录将与内存中的对象不同步。 我敢打赌,您会遇到这样的情况:即使正在设置数据库中的字段,与新激活的用户相对应的 ruby 对象也不会更新(反之亦然)。
我需要查看实际运行的控制器操作,以渲染您设置的与“/”匹配的路线,但我敢打赌,您在该操作中遇到了微妙不一致的情况,这些情况会因 AASM 中的这种不一致而被绊倒。 尝试在该控制器操作开始时重新加载用户对象,看看问题是否消失。 如果没有开始调试,请确保您的状态更改实际上已保存到数据库中。
Acts As State Machine will sometimes have some odd behavior where the saved record written to the database will be out of sync with the object in memory. I bet you have a situation where the ruby object corresponding to the newly activated user is not being updated even though the field in the db is being set (of vice versa).
I'd need to see the controller action that actually runs to render the route you have setup to match "/", but I bet you've got subtly inconsistent cases in that action that are being tripped up by this inconsistency in AASM. Try reloading the user object at the start of that controller action to see if the problem goes away. If not begin debugging by making sure that your state changes are actually being saved out to the db.