Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Extending models in Rails

View gist:990034
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# See http://blog.waxman.me/extending-your-models-in-rails-3 for original post
 
module Extensions
module Popular
 
module ClassMethods
def most_popular(limit=10)
order('points desc').limit(limit).all
end
end
 
def popularity
1+(self.points/100)
end
 
def self.included(base)
base.extend(ClassMethods)
base.extend(Extensions::OtherCoolStuff)
end
 
end
end
 
class User
include Extensions::Popular
end
 
class Tags
include Extensions::Popular
end
ryanjm commented

Could you help me out? How would you write rspec tests for the first one?

Also the comment on your site some how messes up future comments. Might consider deleting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.