Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 向用户发送电子邮件,通知他们在其个人资料上发布了新内容_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 3 向用户发送电子邮件,通知他们在其个人资料上发布了新内容

Ruby on rails 3 向用户发送电子邮件,通知他们在其个人资料上发布了新内容,ruby-on-rails-3,Ruby On Rails 3,在我的Rails 3应用程序中,一个人的个人资料可以有最高级。事实上,Profile模型是这样建立的:它有许多:最高级的,并且最高级的:属于:Profile。我想做的是,当我的用户的个人资料收到新的最高级信息时,给他们发送一封电子邮件。我只是不知道该把什么传递到我的Mailer和Mailer操作中,以使其工作。有人能帮我吗 我一直在跟踪RailsCast发送其他电子邮件,所以我所有的邮件都在控制器中。我不太明白发生了什么事。我知道我需要使用新创建的最高级来查找配置文件以查找用户以查找用户的电子邮

在我的Rails 3应用程序中,一个人的个人资料可以有最高级。事实上,
Profile
模型是这样建立的:它有许多:最高级的
,并且
最高级的
:属于:Profile
。我想做的是,当我的用户的个人资料收到新的最高级信息时,给他们发送一封电子邮件。我只是不知道该把什么传递到我的Mailer和Mailer操作中,以使其工作。有人能帮我吗

我一直在跟踪RailsCast发送其他电子邮件,所以我所有的邮件都在控制器中。我不太明白发生了什么事。我知道我需要使用新创建的最高级来查找配置文件以查找用户以查找用户的电子邮件(这使我认为有一种更简单的方法来完成此操作。我尝试在
最高级#create
操作中分配
@Profile
,但这引发了一个错误

尽管如此,我已经尝试了很多,并在下面发布了我的代码

我的
在我的最高级\u控制器中创建
操作:

def create
  @superlative = Superlative.new(params[:superlative].merge(:author_id => current_user.id))
  if @superlative.save!
    SuperlativeMailer.new_superlative(@user).deliver
    respond_to do |format|
      format.js { }
    end
  else
    respond_to do |format|
      format.js { render 'fail_superlative_create.js.erb' }
    end
  end
end
还有我最高级的邮件员的新最高级动作:

def new_superlative(user)
  @superlative = superlative
  @profile = superlative.profile
  @user = superlative.profile.user
  mail(:to => user.email, :subject => "#{@superlative.name} just gave you a superlative.")
end
然而,在所有这些情况下,我收到了一个错误:

NameError (undefined local variable or method `superlative' for #<SuperlativeMailer:0x103c006a8>):
  app/mailers/superlative_mailer.rb:6:in `new_superlative'
  app/controllers/superlatives_controller.rb:8:in `create'
namererror(未定义的局部变量或#的“最高级”方法):
app/mailers/supremative_-mailer.rb:6:in'new_-supremative'
app/controllers/suprematives_controller.rb:8:in'create'

您需要将
最高级的
对象传递给邮件程序,而不是
用户

def new_superlative(superlative)
  @superlative = superlative
  @profile = superlative.profile
  @user = superlative.profile.user
  mail(:to => @user.email, :subject => "#{@superlative.name} just gave you a superlative.")
end
在控制器中

superativemailer.new\u superative(@superative).deliver