mardi 4 août 2015

Rails: Order by associate, first not downloaded

I have problem with displaying files. My app:

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

And when an user logs in I want to display all files, but files downloaded by current user should be displayed last. The file table has about 500 records so I need simple and fast method to achieve this. How to do this?

The technologies I am using

  • Rails 4.2.1
  • Ruby 2.2.2
  • PostgreSQL


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire