动作邮件程序不在rails_admin中工作,仅在本机路径上工作

时间:2014-10-26 23:38:59

标签: ruby-on-rails actionmailer rails-admin

所有用户的操作邮件程序仅在本机路径/ articles / new中工作,但不在rails_admin仪表板中。当我在管理员中创建文章时,我没有收到任何错误。它不会像使用管理操作调用方法那样接缝。

这是控制器:

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

这是模特:

class Article < ActiveRecord::Base
    has_many :comments, dependent: :destroy
  validates :title, presence: true,
                    length: { minimum: 5 }
end

这是我添加到应用程序控制器的行:

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

帮助!

Article Mailer:
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 article has been posted"
  end
end 

0 个答案:

没有答案