![](/img/trans.png)
[英]Jquery javascript - How can I let users 'undo' their modifications?
[英]How can I let users chose their own email template?
因此,我有一个应用程序,用户可以在其中创建电子邮件,我希望他们能够选择其电子邮件模板设计。
我该如何实施? 我知道这可能有点复杂,但是我愿意接受想法。
newsletter.rb
class Newsletter < ActiveRecord::Base
has_many :subscriptions
has_many :users, through: :subscriptions
has_many :posts, dependent: :destroy
belongs_to :user
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates_presence_of :image, :name
scope :for, ->(user) do
if user
Newsletter.all
end
end
end
user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable,
:validatable
has_many :subscriptions
has_many :subscribed_newsletters, through: :subscriptions, class_name: "Newsletter"
has_many :newsletters
validates :email, uniqueness: true, presence: true
validates_presence_of :password, on: :create
end
post.rb <----这就是模板内部的内容,即帖子模型中的内容。
class Post < ActiveRecord::Base
belongs_to :newsletter
end
假设这是用户希望发送哪个模板的偏好。
User.newsletter_template = 'my_custom_template'
现在,创建一个通用的activemailer模板,该模板仅呈现用户选择的模板
newsletter_email.html.erb
<%= render "/some/path/#{user.newsletter_template}.html.erb" %>
my_custom_template.html.erb
<html>stuff</html>
my_other_template.html.erb
<html>alt template</html>
我知道这不是深入的解释。 不要害羞地问!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.