选择后的ActiveRecord计数

时间:2015-10-09 16:20:08

标签: ruby-on-rails activerecord

我有一个这样的分页助手:

  def paginate(collection)
    count = collection.count
    collection.offset(@offset).limit(@per_page)
  end

for collection我只想选择某些字段,但如果我选择了count,则Model.all.select(:foo, :bar)的行为会发生变化。有没有办法可以通过,例如collection package com.hmkcode;   import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.tool.xml.XMLWorkerHelper;   public class App {     public static void main( String[] args ) throws DocumentException, IOException     {       // step 1         Document document = new Document();         // step 2         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf.pdf"));         // step 3         document.open();         // step 4         XMLWorkerHelper.getInstance().parseXHtml(writer, document,                 new FileInputStream("index.html"));         //step 5          document.close();           System.out.println( "PDF Created!" );     } } 在这里?

0 个答案:

没有答案