我有一个电子邮件模型,供用户在添加或更新文章时注册以接收电子邮件通知。该电子邮件正常工作,但我收到一条错误消息,其中包含我在我的email.rb文件中生成的取消订阅方法。我发现在2012年发布的另一个stackoverflow问题中的取消订阅解决方案,但我没有看到如何正确工作解决方案。Rails取消订阅与ActionMailer的链接
电子邮件型号:
class Email < ActiveRecord::Base
validates :email, uniqueness: true
validates :email, presence: true
def unsubscribe
Email.find(params[:id]).update_attributes(permissions: false)
end
end
文章型号:
class Article < ActiveRecord::Base
...
has_many :emails
after_create :send_new_notifications!
after_update :send_update_notifications!
def send_update_notifications!
email = Email.where(permissions: true)
email.each do |email|
UpdatedArticleMailer.updated_article(email, self).deliver_later
end
end
def send_new_notifications!
email = Email.where(permissions: true)
email.each do |email|
ArticleNotificationMailer.new_article(email, self).deliver_later
end
end
end
在更新文章电子邮件退订链接:
<%= link_to "Unsubscribe", email_url(@email.unsubscribe) %>
错误消息:
undefined local variable or method `params' for #<Email:0x007ff5c2955e88>
def unsubscribe
Email.find(params[:id]).update_attributes(permissions: false)
end
end
关于:会员,这是我声明的东西,例如电子邮件或这是从轨道上的东西? – jgrant
我认为这工作,但我看到一个模板错误。我假设这是因为我没有在我的退订方法中设置句柄错误,重定向成功等? – jgrant
对,您需要有一个名为unsubscribe.erb的视图,或者在成功时重定向它。 – GoGoCarl