【问题标题】:Twitter-Like "Reply and Retweet" Rails 3类似 Twitter 的“回复和转发”Rails 3
【发布时间】: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


    【解决方案1】:

    您应该为回复和转发创建另一个模型。因为一张照片有很多来自不同人的转发,也有不同的转发。

    在这种情况下,我将创建一个照片模型、一个转推模型和一个回复模型。

    【讨论】:

      猜你喜欢
      • 2022-10-05
      • 1970-01-01
      • 2011-08-25
      • 2011-07-15
      • 1970-01-01
      • 2011-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多