我在显示可通过我的应用程序访问的文件时遇到问题。当用户登录时,我想显示他们的所有文件。当前用户下载的文件应该最后显示。文件表有大约 500 条记录,所以我需要简单快速的方法来实现这一点。
class User
has_many :downloads
has_many :downloaded_files, :through => :downloads, source: :file
end
class File
attr_accessor :downloaded
has_many :downloads
has_many :users, :through => :downloads
end
class Download
belongs_to :user
belongs_to :file
end
我正在使用的技术
- 导轨 4.2.1
- 红宝石 2.2.2
- PostgreSQL