2013-10-17 111 views
0

我試圖做一個接觸的形式爲我的應用程序,但我得到一個錯誤:undefined method 'send_email' for ProductMailer:Class.NoMethodError在StaticPagesController#email_contact,軌道4,5

我Staticpagescontroller是:

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

我的電子郵件使用者是:

class Contact < ActionMailer::Base 
default from: "[email protected]" 

# 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: "[email protected]" 
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" 

回答

0

只需重命名你的class Contact < ActionMailer::Baseclass ProductMailer < ActionMailer::Base

0

重命名類聯繫到ProductMailer

0

您已經指定了錯誤的類名。在你的郵件類中,你已經定義了Contact類,但是你在控制器動作中使用了ProductMailer。它應該是:

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