【发布时间】:2015-02-06 06:32:15
【问题描述】:
所以我有一个用户可以创建电子邮件的应用程序,我希望他们能够选择他们的电子邮件模板设计。
我该如何实现呢?我知道这可能有点复杂,但我对想法持开放态度。
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
用户.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
【问题讨论】:
-
你问的是如何实现模型关系或视图?
-
干杯@eabraham!两者兼而有之,我不确定是否应该为此生成一个新模型,即 template.rb,最终,当用户为他们的时事通讯创建帖子时,我想让他们能够选择他们的电子邮件模板。因此,任何关于该做什么或从哪里开始完成此任务的提示都会非常有帮助!
标签: jquery html ruby-on-rails ruby ruby-on-rails-4