0

我正在尝试为我的应用程序制作联系表,但出现错误:undefined method 'send_email' for ProductMailer:Class.

我的静态页面控制器是:

def email_contact
  ProductMailer.send_email().deliver
  redirect_to contact_url
end

我的电子邮件是:

class Contact < ActionMailer::Base
default from: "from@example.com"

# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
#   en.contact.send_email.subject
#

def send_email
  @greeting = "Hi"

  mail to: "example@example.com"
end
end

我的路线是:

 match '/show/:id', to: 'stores#show', via: 'get', :as=> 'show'
 get  "emailproduct/:id" => "products#email_product", :as => "email_product"
 get "emailcontact" => "static_pages#email_contact", :as => "email_contact"
4

2 回答 2

0

将类 Contact 重命名为 ProductMailer

于 2013-10-17T17:40:05.493 回答
0

您指定了错误的类名。在您的邮件程序类中,您已定义Contact类,但已ProductMailer在控制器操作中使用。它应该是:

def email_contact
  Contact.send_email().deliver
  redirect_to contact_url
end
于 2013-10-17T17:45:58.817 回答