我是 Rails 的新手,试图为我的应用程序制作联系表格,但如果没有关联模型,我无法在 Emailer 类中捕获来自联系表格的参数(如姓名和消息)。对此有什么建议吗?这是类和控制器的列表。我的电子邮件类是:
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(contact)
@greeting = "Hi"
mail to: "ostadfree@gmail.com"
end
end
静态页面控制器是:
def email_contact()
Contact.send_email().deliver
redirect_to contact_url
end
Contact.html.erb 最后包含一个表单和两个按钮:
<%= submit_tag "Submit", class: "btn btn-large btn-primary" %>
<%= link_to 'Send Email', email_contact_path %>
和 send_email.text.erb 是:
Contact#send_email
<%= @greeting %>, find me in app/views/app/views/contact/send_email.text.erb
<%#= "Name :" + @name.to_s %>
谢谢。