将变量传递给设计i18n消息:signed_up_but_unconfirmed

时间:2014-07-10 03:58:11

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

是否有人知道如何将变量传递给' signed_up_but_unconfirmed' (来自config / locales / devise.en.yml)

我想要发送确认电子邮件的电子邮件地址的变量,而不是标准邮件,如下所示:

signed_up_but_unconfirmed:"感谢您注册,发送电子邮件至%{sent_email}"

我以为我可能需要覆盖registrations_controller.rb中的创建操作,无法查看位置。

由于

1 个答案:

答案 0 :(得分:0)

class RegistrationsController < Devise::RegistrationsController 
  # POST /resource
  def create
    build_resource(sign_up_params)
    if resource.save
      # this block will be used when user is saved in database
      if resource.active_for_authentication?
        # this block will be used when user is active or not required to be confirmed
        set_flash_message :notice, :signed_up if is_navigational_format?
        sign_up(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        # this block will be used when user is required to be confirmed
        user_flash_msg if is_navigational_format? #created a custom method to set flash message
        expire_session_data_after_sign_in!
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      # this block is used when validation fails
      clean_up_passwords resource
      respond_with resource
    end
  end

  private

  # set custom flash message for unconfirmed user
  def user_flash_msg
    if resource.inactive_message == :unconfirmed
      #check for inactive_message and pass email variable to devise locals message
      set_flash_message :notice, :"signed_up_but_unconfirmed", email: resource.email
    else
      set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}"
    end
  end
end

Devise: Pass unconfirmed email address back to sign in page

  1. 覆盖创建方法。
  2. 定义自定义功能并添加额外的电子邮件参数
  3. 将其传递给Devise Controller的set_flash消息 这应该可以工作或至少为您提供足够的信息来自行修复。