Skip to content

Instantly share code, notes, and snippets.

@ssaunier
Created June 1, 2014 23:40
Show Gist options
  • Save ssaunier/c3b1b439fb8d921515fc to your computer and use it in GitHub Desktop.
Save ssaunier/c3b1b439fb8d921515fc to your computer and use it in GitHub Desktop.
User like Postcards
class Like < ActiveRecord::Base
belongs_to :user
belongs_to :postcard
end
class Postcard < ActiveRecord::Base
has_many :likes
end
class User < ActiveRecord::Base
has_many :likes
end
@ssaunier
Copy link
Author

ssaunier commented Jun 1, 2014

Pour compter le nombre de likes d'une postcard:

postcard = Postcard.find(23)
like_count = postcard.likes.size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment