lib/santey_view/viewable.rb in santey_view-0.1.0 vs lib/santey_view/viewable.rb in santey_view-0.2.0
- old
+ new
@@ -127,18 +127,20 @@
view = viewing_class.new
view.viewer_id = viewer.id if viewer && !viewer.id.nil?
view.ip = ip
viewings << view
target = self if attributes.has_key? 'views'
- target.views = ( (target.views || 0) + 1 ) if target
+ #target.views = ( (target.views || 0) + 1 ) if target
+ target.increment(:views, 1) if target
view.save
- target.save_without_validation if target
+ target.save(false) if target
return true
else
return false
end
end
end
+
# Check if an item was already viewed by the given viewer
def viewed_by? ip, viewer = nil
if viewer && !viewer.nil? && !(santey_view_options[:viewer_class].constantize === viewer)
raise ViewedError, "the viewer object must be the one used when defining santey_view (or a descendent of it). other objects are not acceptable"