【发布时间】:2017-03-18 18:41:59
【问题描述】:
我正在构建一个示例 Rails 应用程序来模仿我最喜欢的一些应用程序。我想实现对照片的照片回复和照片的转发——类似于您通过 Twitter 回复和转发的方式。我应该创建一个单独的关系模型来捕获照片回复和转发,还是应该处理照片模型中的所有内容。
class Photo < ActiveRecord::Base
attr_accessible :caption, :source, :source_remote_url, :source_file_name,
has_attached_file :source
validates_attachment_content_type :source
belongs_to :user
has_many :replies
has_many :reposts
def source_remote_url=(url_value)
self.source = URI.parse(url_value) unless url_value.blank?
super
end
def replies
join_table
end
def replies?(other_user)
join_table.find_by_replied_id(other_user.id)
end
def reply!(other_user)
join_table.create!(replied_id: other_user.id)
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 activerecord