ハイ、
私のコード:
@profile.images
このように、一度に10枚の画像だけを10枚のオフセットで取得したいと思います
@profile.images(:limit => 10, :offset => 10)
そして、このようではありません
has_many :images, :limit => 10, :offset => 10
次に、そのプロファイルのすべての画像を何とか数えたいと思います。
@profile.count_images
ありがとう (:
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
終わり
ここで、この動作を他の has_many 関係に追加したいと思います。しかし、コードをコピーして貼り付けたくありません...何か考えはありますか? :P