Jquery 如何让用户选择自己的电子邮件模板?

Jquery 如何让用户选择自己的电子邮件模板?,jquery,html,ruby-on-rails,ruby,ruby-on-rails-4,Jquery,Html,Ruby On Rails,Ruby,Ruby On Rails 4,因此,我有一个应用程序,用户可以创建电子邮件,我希望他们能够选择他们的电子邮件模板设计 我该如何实现这一点?我知道这可能有点复杂,但我对想法持开放态度 时事通讯.rb class Newsletter < ActiveRecord::Base has_many :subscriptions has_many :users, through: :subscriptions has_many :posts, dependent: :destroy belongs_to :use

因此,我有一个应用程序,用户可以创建电子邮件,我希望他们能够选择他们的电子邮件模板设计

我该如何实现这一点?我知道这可能有点复杂,但我对想法持开放态度

时事通讯.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
class时事通讯{:medium=>“300x300>”,:thumb=>“100x100>”},:default\u url=>“/images/:style/missing.png”
验证\u附件\u内容\u类型:图像,:内容\u类型=>/\Aimage\/.\Z/
验证是否存在:image,:name
范围:for,->(用户)do
如果用户
时事通讯
结束
结束
结束
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
class用户

post.rb让我们假设这是用户希望发送的模板的首选项

User.newsletter_template = 'my_custom_template'
现在,创建一个通用的activemailer模板,它只呈现用户选择的模板

时事通讯\u email.html.erb

<%= render "/some/path/#{user.newsletter_template}.html.erb" %>
<html>stuff</html>
<html>alt template</html>

my\u custom\u template.html.erb

<%= render "/some/path/#{user.newsletter_template}.html.erb" %>
<html>stuff</html>
<html>alt template</html>
东西
my\u other\u template.html.erb

<%= render "/some/path/#{user.newsletter_template}.html.erb" %>
<html>stuff</html>
<html>alt template</html>
alt模板

我知道这不是一个深入的解释。别不好意思问

你是在问如何实现模型关系还是视图?干杯@eabraham!两者兼而有之,我不确定是否应该为此生成一个新模型,即template.rb,最终,当用户为他们的新闻稿创建帖子时,我希望允许他们选择他们的电子邮件模板。因此,任何关于做什么或从哪里开始实现这一目标的提示都将非常有用!谢谢,+1这很有帮助!我确实有几个问题。1.新闻稿模板方法在哪里定义?这是一个用户模型方法还是我应该创建一个单独的新闻稿模板模型?2.用户实际上是如何选择模板的?即复选框?或者这是怎么回事。为用户模型创建属性。随便你怎么说都行。2.我可能会使用一个表单,让用户从您创建的模板的预设列表中选择一个值。好的,很好,只是要清楚,在我的例子中,它将是用户表或posts表上的一个新列,即新闻稿\ U模板:字符串,我会用我的时事通讯预先填充它,然后在一个选择表单上,用户可以用模板选择,对吗?我会接受的。