要发送新的确认说明,必须输入电子邮件。我想避免这种情况,因为我的用户当时已登录,因此不需要电子邮件询问。我只想向current_user.email
我不想做像这样的客户端事情:
= f.email_field :email, value: current_user.email, class: "hidden"
我需要服务器端解决方案。
谢谢你们!
答案 0 :(得分:1)
根据devise codebase,可以按如下方式向用户调用发送确认电子邮件:
user = User.find(1)
user.send_confirmation_instructions
所以你真的不需要从表格中收到电子邮件。
答案 1 :(得分:0)
您可以访问设备方法,这应该可以。
请参阅文档here
<强>的routes.rb 强>
devise_for :users, controllers: { confirmations: "confirmations" }
在视图中
= link_to "resend confirmation", user_confirmation_path, data: { method: :post }
答案 2 :(得分:0)
我最终得到了这个:
首先,覆盖设计控制器:
<强>配置/ routes.rb中强>
devise_for :users, controllers: { confirmations: "users/confirmations" }
<强>控制器/用户/ confirmations_controller.rb 强>
class Users::ConfirmationsController < Devise::ConfirmationsController
def create
redirect_to new_user_session_path unless user_signed_in?
if current_user.confirmed?
redirect_to root_path
else
current_user.send_confirmation_instructions
redirect_to after_resending_confirmation_instructions_path_for(:user)
end
end
end
protected
# The path used after resending confirmation instructions.
def after_resending_confirmation_instructions_path_for(resource_name)
flash[:notice] = "Instructions sent successfully."
is_navigational_format? ? root_path (or whatever route) : '/'
end
end
然后从视图中删除电子邮件字段。
<强>视图/设计/确认/ new.html.haml 强>
= form_for(resource, as: resource_name, url: confirmation_path(resource_name), method: :post }) do |f|
= f.submit "Resend confirmation instructions"
感谢大家的回答。