Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Created February 25, 2009 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balinterdi/70200 to your computer and use it in GitHub Desktop.
Save balinterdi/70200 to your computer and use it in GitHub Desktop.
def shared_to?(object, by_user=nil)
shareable = ActiveRecord::Base.send(:class_name_of_active_record_descendant, self.class).to_s
to = ActiveRecord::Base.send(:class_name_of_active_record_descendant, object.class).to_s
if by_user
s = Share.find(:first, :conditions=>["shareable_type = ? and shareable_id = ? and shared_to_type = ? and shared_to_id = ? and user_id=?",
shareable, id, to, object.id, by_user.id])
else
s = Share.find(:first, :conditions=>["shareable_type = ? and shareable_id = ? and shared_to_type = ? and shared_to_id = ?",
shareable, id, to, object.id])
end
return !s.nil?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment