【问题标题】:Defining mailer in sorcery在巫术中定义邮件程序
【发布时间】:2016-08-24 01:10:56
【问题描述】:

我正在使用魔法构建一个 Rails 应用程序。当我转到 users/new 时,有一个参数错误说明 "要使用 reset_password 子模块,您必须定义一个邮件程序 (config.reset_password_mailer = YourMailerClass)"

进入 config/initializers/sorcery.rb 并包含代码 user.reset_password_mailer = UserMailer 但我仍然收到错误消息。 在 UserMailer 类中,我定义了 reset_password_email 方法

 def reset_password_email(user)
    @user = User.find user.id
    @url  = edit_password_reset_url(@user.reset_password_token)
      mail(:to => user.email,
           :subject => "Your password has been reset")
end

并更新了 sorcery.rb 文件

user.reset_password_email_method_name = :reset_password_email

我仍然收到相同的错误消息。

在用户控制器中:

class UsersController < ApplicationController

  def index
    @users = User.all
  end

  def new
    @user = User.new
  end


  def create
    @user = User.new(user_params)
        if @user.save
            redirect_to products_url, notice: "Signed Up!"
        else
            render "new"
        end
  end

  def show
    @user = User.find(params[:id])
  end

  private

  def user_params
    params.require(:user).permit(:email, :user_name, :password, :password_confirmation)
  end

end

我的用户模型是:

class User < ActiveRecord::Base
  authenticates_with_sorcery!
  has_many :projects

  validates :password, confirmation: true
  validates :password_confirmation, presence: true
  validates :email, uniqueness: true

end

【问题讨论】:

    标签: ruby-on-rails sorcery


    【解决方案1】:

    您似乎按照Sorcery docs 配置了邮件程序。但请记住config/initializers/sorcery.rb,就像config/initializers 中的所有文件一样,只会在应用程序启动时处理。

    看起来你的配置是正确的,如果我在添加配置之前运行应用程序,我会得到同样的错误,但在重新启动 Rails 服务器后它确实对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-31
      • 1970-01-01
      • 2013-04-29
      • 2023-03-22
      • 1970-01-01
      • 2015-02-14
      相关资源
      最近更新 更多