Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Extending models in Rails
# 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

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.