尝试将UserMailer包含到我的控制器时出现语法错误

时间:2013-04-09 19:08:03

标签: ruby-on-rails ruby ruby-on-rails-3 syntax-error

我正在尝试发送电子邮件,如果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

1 个答案:

答案 0 :(得分:2)

消除(),并将地址设为字符串。

mail :to => "admin@domain.com", :subject => "Post needs review"