Class: Clipping
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Clipping
- Defined in:
- app/models/clipping.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_image ⇒ Object
- #has_been_favorited_by(user = nil, remote_ip = nil) ⇒ Object
- #image_uri(size = '') ⇒ Object
- #next_clipping ⇒ Object
- #owner ⇒ Object
- #previous_clipping ⇒ Object
- #save_image ⇒ Object
- #title_for_rss ⇒ Object
Class Method Details
.find_recent(options = {:limit => 5}) ⇒ Object
34 35 36 |
# File 'app/models/clipping.rb', line 34 def self.find_recent( = {:limit => 5}) where("created_at > '#{7.days.ago.iso8601}'").order("created_at DESC").limit([:limit]) end |
.find_related_to(clipping, options = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/clipping.rb', line 22 def self.(clipping, = {}) .reverse_merge!({:limit => 8, :order => 'clippings.created_at DESC', :conditions => [ 'clippings.id != ?', clipping.id ] }) limit([:limit]). order([:order]). where([:conditions]). tagged_with(clipping..collect{|t| t.name }, :any => true) end |
Instance Method Details
#add_image ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/clipping.rb', line 62 def add_image begin clipping_image = ClippingImage.new uploaded_data = clipping_image.data_from_url(self.image_url) clipping_image.asset = uploaded_data self.image = clipping_image rescue nil end end |
#has_been_favorited_by(user = nil, remote_ip = nil) ⇒ Object
57 58 59 60 |
# File 'app/models/clipping.rb', line 57 def has_been_favorited_by(user = nil, remote_ip = nil) f = Favorite.find_by_user_or_ip_address(self, user, remote_ip) return f end |
#image_uri(size = '') ⇒ Object
49 50 51 |
# File 'app/models/clipping.rb', line 49 def image_uri(size = '') image && image.asset.url(size) || image_url end |
#next_clipping ⇒ Object
41 42 43 |
# File 'app/models/clipping.rb', line 41 def next_clipping self.user.clippings.where('created_at > ?', self.created_at).order('created_at ASC').first end |
#owner ⇒ Object
45 46 47 |
# File 'app/models/clipping.rb', line 45 def owner self.user end |
#previous_clipping ⇒ Object
38 39 40 |
# File 'app/models/clipping.rb', line 38 def previous_clipping self.user.clippings.order('created_at DESC').where('created_at < ?', self.created_at).first end |
#save_image ⇒ Object
73 74 75 76 77 78 |
# File 'app/models/clipping.rb', line 73 def save_image if valid? && image image.attachable = self image.save end end |
#title_for_rss ⇒ Object
53 54 55 |
# File 'app/models/clipping.rb', line 53 def title_for_rss description.empty? ? created_at.to_formatted_s(:long) : description end |