StaticPagesController中的NoMethodError#email_contact,rails 4

时间:2013-10-17 17:33:57

标签: ruby-on-rails

我正在尝试为我的应用制作联系表单,但收到错误:undefined method 'send_email' for ProductMailer:Class.

My Staticpagescontroller是:

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"

2 个答案:

答案 0 :(得分:0)

将类联系人重命名为ProductMailer

答案 1 :(得分:0)

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

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