2017-03-18 3 views
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 

答えて

0

返信とリツイートの別のモデルを作成する必要があります。写真には、さまざまな人々からのリトワットと、さまざまなリトワットがあります。

この場合、写真モデル、リッツモデル、返信モデルを作成します。

関連する問題