设计可确认。如何删除电子邮件字段?

时间:2015-03-17 02:12:05

标签: ruby-on-rails ruby-on-rails-4 devise devise-confirmable

要发送新的确认说明,必须输入电子邮件。我想避免这种情况,因为我的用户当时已登录,因此不需要电子邮件询问。我只想向current_user.email

发送新的说明

我不想做像这样的客户端事情:

= f.email_field :email, value: current_user.email, class: "hidden"

我需要服务器端解决方案。

谢谢你们!

3 个答案:

答案 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"

感谢大家的回答。