我是 Rails 新手,我想在我的应用程序上添加“订阅”功能。
每当有人订阅我的网站时,我确实设法(通过电子邮件)收到通知。我现在要做的是向用户发送通知以表示感谢。
我有的:
/models/contact.rb
class Contact < MailForm::Base
attribute :name
attribute :email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :message
attribute :nickname, :captcha => true
def headers
{
:subject => "New Subscription:",
:to => "email@example.com",
:from => "email@example.com"
}
end
end
/controllers/contacts_controller.rb
class ContactsController < ApplicationController
def create
@contact = Contact.new(params[:contact])
@contact.request = request
if @contact.deliver
redirect_to(:back)
else
#TODO fail notification
redirect_to(:back)
end
end
end
我尝试了什么:
- 使用 ActionMailer::Base 类发送电子邮件,但我无法从表单中检索 params[:contact][:email],因此无法通过电子邮件发送回复
- 使用mailform发送多封电子邮件,但我没有做到
我的问题是我没有用户模型,也不需要用户模型,因为此应用程序上没有存储空间。