0

如果 post = review,我正在尝试发送电子邮件,但我收到语法错误。代码应该怎么改?尝试添加UserMailer.review_email(@user).deliver导致此错误

这是我得到的错误

SyntaxError in PostsController#create  
syntax error, unexpected tIVAR, expecting keyword_do or '{' or '('
    mail(:to => admin@domain.com, :subject => "Review")
  syntax error, unexpected tASSOC, expecting tCOLON2 or '[' or '.'
    mail(:to => admin@domain.com, :subject => "Review")
syntax error, unexpected ')', expecting keyword_end

这是我试图放置 UserMailer 代码的控制器

def create
    @post = current_user.posts.build(params[:post])
    if @post.save
      if @post.review
        UserMailer.review_email(@user).deliver
        flash[:notice] = "Post will be reviewed"
      redirect_to root_path
      else
        flash[:success] = "Posted"
      redirect_to root_path
    end
    else
      @feed_items = []
      render 'static_pages/home'
    end
  end

用户邮件模型

class UserMailer < ActionMailer::Base
  default from: "account@domain.com"

  def review_email(user)
    @user = user
    mail(:to => admin@domain.com, :subject => "Post needs review")
  end

end
4

1 回答 1

2

去掉 (),把地址变成一个字符串。

mail :to => "admin@domain.com", :subject => "Post needs review"
于 2013-04-09T19:46:06.767 回答