Class: Bookmark
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Bookmark
- Defined in:
- app/models/bookmark.rb
Overview
This model represents bookmarks. User can bookmark objects by clicking on a star beside the object’s title. Their bookmarks are listed for them in a quick menu, thus users have quick access to bookmarked objects.
Such bookmarkable objects may be other users, or pages, groups, et cetera.
Class Method Summary collapse
- .find_all_by_bookmarkable(bookmarkable) ⇒ Object
- .find_all_by_user(user) ⇒ Object
-
.find_by(args) ⇒ Object
Finder Methods ==========================================================================================.
- .find_by_user_and_bookmarkable(user, bookmarkable) ⇒ Object
Instance Method Summary collapse
-
#serializable_hash(options = {}) ⇒ Object
API Export // Data Serialization ==========================================================================================.
Methods inherited from ActiveRecord::Base
Class Method Details
.find_all_by_bookmarkable(bookmarkable) ⇒ Object
41 42 43 |
# File 'app/models/bookmark.rb', line 41 def self.find_all_by_bookmarkable( bookmarkable ) self.where( :bookmarkable_type => bookmarkable.class.name, :bookmarkable_id => bookmarkable.id ) end |
.find_all_by_user(user) ⇒ Object
37 38 39 |
# File 'app/models/bookmark.rb', line 37 def self.find_all_by_user( user ) self.where( :user_id => user.id ) end |
.find_by(args) ⇒ Object
Finder Methods
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/bookmark.rb', line 18 def self.find_by( args ) if args[ :user ].present? user = args[ :user ] args[ :user_id ] = user.id args.delete( :user ) end if args[ :bookmarkable ].present? bookmarkable = args[ :bookmarkable ] args[ :bookmarkable_id ] = bookmarkable.id args[ :bookmarkable_type ] = bookmarkable.class.name args.delete( :bookmarkable ) end super args end |
.find_by_user_and_bookmarkable(user, bookmarkable) ⇒ Object
33 34 35 |
# File 'app/models/bookmark.rb', line 33 def self.find_by_user_and_bookmarkable( user, bookmarkable ) (self.find_all_by_user( user ).find_all_by_bookmarkable( bookmarkable )).first end |
Instance Method Details
#serializable_hash(options = {}) ⇒ Object
API Export // Data Serialization
Include some associated data in serialized representations of this object, since this additional information is most likely required by the API and external components.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/bookmark.rb', line 53 def serializable_hash( = {} ) .merge!( { :include => { :bookmarkable => { :methods => [ :title, :url ] } } } ) super( ) end |