2017-03-18 2 views
0

내가 가장 좋아하는 앱 중 일부를 모방 한 샘플 레일즈 애플리케이션을 만들고 있습니다. 트위터를 통해 답장하고 리트 윗하는 방식과 비슷하게 사진의 사진과 회신에 사진 답장을 구현하고 싶습니다. 사진 답장과 재 게시를 캡처하는 별도의 관계 모델을 작성해야합니까, 아니면 사진 모델의 모든 것을 처리해야합니까?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

답장과 리트 윗용으로 다른 모델을 만들어야합니다. 사진에는 ​​다른 사람들의 많은 리트 윗과 다른 리트 윗이 있기 때문입니다.

이 경우 사진 모델, 리트 윗 모델 및 응답 모델을 만듭니다.