rails 分页

①、下载插件: will_paginate(附件), 解压到.\vendor\plugins下

       或者在线安装: ruby script/plugin install svn://errtheblog.com/svn/plugins/will_paginate  

  

②、重启服务器

 

③、修改相应的controller,如下:

      def index
           @companies = Company.find(:all)
           @companies = Company.paginate :page => params[:page]|| 1, :per_page => 20

           respond_to do |format|
              format.html # index.html.erb
              format.xml  { render :xml => @companies }
      end

 

④、在index视图中使用:

     %td{:height=>"70", :align=>"center", :valign=>"middle"}
           -#="共#{ @companies.length }条信息 "  
           = will_paginate @companies, :prev_label=>'<<上一页', :next_label=>'下一页>>'

你可能感兴趣的:(html,xml,SVN,Ruby,Rails)