簡體   English   中英

如何讓用戶選擇自己的電子郵件模板?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM