Action Mailer对所有用户不起作用

时间:2014-10-25 21:05:07

标签: ruby-on-rails actionmailer

生成邮件程序,以便在创建"文章时通知所有用户"。如果它工作,现在它停止了...不知道发生了什么。

这是动作管理员:

class ArticleMailer < ActionMailer::Base
  default from: "Coach@gmail.com"


  # Subject can be set in your I18n file at config/locales/en.yml
  # with the following lookup:
  #
  #   en.referral_mailer.referral_confirmation.subject
  #
  def article_confirmation(user,article)
    @user = user 
    @article = article 
    mail to: user.email, subject: "Coach #{user.first_name}, a new goal has been posted"
  end
end 

调用邮件的控制器:

class ArticlesController < ApplicationController

  load_and_authorize_resource
  skip_authorize_resource :only => [:index, :show]

def new
    @article = Article.new
end

    def create
        @article = Article.new(article_params)
    #  authorize! :create, @article

        if @article.save
        #send email to referral email
        all_users = User.all
        all_users.each do |user|
          ArticleMailer.article_confirmation(user,@article).deliver
       end 
       redirect_to @article
        else
         render 'new'
        end
    end
.....

1 个答案:

答案 0 :(得分:0)

看起来它正在使用它添加到应用程序控制器:

before_action do  
    resource = controller_name.singularize.to_sym
    method = "article_params"
    params[resource] &&= send(method) if respond_to?(method, true)
end

现在......没有使用rails_admin gem ...

在管理端工作