Rails 邮件程序“未定义方法”错误。

发布于 2024-12-21 11:32:25 字数 772 浏览 3 评论 0原文

我正在尝试在 Rails 3.1 中设置一个简单的邮件程序。

我的邮件程序中有以下代码...

class Notify < ActionMailer::Base

  default :from => "[email protected]"

  def send
    @email = email
    @ip = ip
    mail(:to => "[email protected]", :subject => "#{email} just signed up")
  end

end

然后在我的控制器中...

Notify.send(params[:email], ip).deliver

由于某种原因,当在我的控制器中调用该行时我无法计算出以下错误...

undefined method `*string I passed in*' for Notify:Class

我有什么想法这里做错了吗?

I'm trying to setup a simple mailer in rails 3.1.

I have the following code in my mailer...

class Notify < ActionMailer::Base

  default :from => "[email protected]"

  def send
    @email = email
    @ip = ip
    mail(:to => "[email protected]", :subject => "#{email} just signed up")
  end

end

Then in my controller I have...

Notify.send(params[:email], ip).deliver

For some reason that I can't work out when that line is called in my controller I get the following error...

undefined method `*string I passed in*' for Notify:Class

Any ideas what I'm doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痴梦一场 2024-12-28 11:32:25

send() 已由 Ruby 定义,用于传递消息。

因此,对于 ruby​​ 来说,您似乎正在尝试调用一个方法。

User.first.send(:name)

与调用相同,

User.first.name

只需重命名您的方法。

send() is already defined by Ruby, and it is used to pass messages around.

So, to ruby it looks like you are trying to call a method.

User.first.send(:name)

is the same thing as calling

User.first.name

Just rename your method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文