Hy,
My code:
@profile.images
and i would like to get only 10 images at time and with a 10 offset, like this
@profile.images(:limit => 10, :offset => 10)
and not like this
has_many :images, :limit => 10, :offset => 10
Then I would like to count in someway all the images for that profile.
@profile.count_images
Thanks (:
has_many :images, :foreign_key => 'on_id', :conditions => 'on_type = "profile"' do
def paginate(page = 1, limit = 10, offset = nil)
page = nil if page < 1
limit = 1 if limit < 1
offset = 0 if(offset && offset < 0)
offset = 0 if (!page)
offset = limit * (page - 1) if (page)
all(:limit=> limit, :offset => offset)
end
end
Now I would like to add this behaviour to other has_many relationships. But I would not like to copy paste the code... Any idea? :P