0
私の好きなアプリのいくつかを模倣したサンプルレールアプリケーションを構築しています。私は写真の写真と写真の投稿に写真の返信をしたいと思っています - あなたがTwitterを使って返信してリツイートするのと同じように。写真の返信と再投稿をキャプチャする別のリレーションシップモデルを作成するか、写真モデルのすべてを処理する必要があります。Twitterのような "Reply and Retweet" Rails 3
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