Reputation: 167
How to update only :share_count, maybe this should be done with upsert
?
I use ruby on rails and mongoid
class FeedEntry
include Mongoid::Document
require 'social_shares'
field :name, type: String
field :url, type: String
field :share_count, type: Integer
before_save :load_shares
def load_shares
self.share_count = SocialShares.total url, %w(sharedcount)
end
def self.update_shares_today
@feed_entries = FeedEntry.today.all
@feed_entries.each do |feed_entry|
feed_entry.update
end
end
end
Upvotes: 1
Views: 1514
Reputation: 2030
count = SocialShares.total url, %w(sharedcount)
update_attributes share_count: count
Upvotes: 1