代码之家  ›  专栏  ›  技术社区  ›  Sam å±±

rails3-将对插件奇怪的输出分页

  •  0
  • Sam å±±  · 技术社区  · 15 年前

    我有在应用程序中工作的will-paginate插件,但当我对资源进行分页时,它只是将html作为文本输出,不提供指向下一页等的链接。

    当我手动输入这个插件正在运行的url时 <%= will_paginate @products %> 进入下一个12 3…最后的

    这是输出

    <span class="disabled prev_page">&amp;laquo; Previous</span> <span class="current">1</span> <a href="/products?page=2" rel="next">2</a> <a href="/products?page=2" class="next_page" rel="next">Next &amp;raquo;</a>

    控制器: DEF指数

    @products = Product.all.paginate :per_page => 5, :page => params[:page]
    @product_categories = ProductCategory.find(:all)
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @products }
    end
    

    结束

    看法

    <%= will_paginate @products %> 
    <%= will_paginate %> #for some reasons this works too
    
    4 回复  |  直到 14 年前
        1
  •  2
  •   Andreas Klinger    14 年前
    source 'http://rubygems.org'
    
    gem 'rails', '3.0.0.beta2'
    gem "will_paginate", '3.0.pre' 
    

    如果遇到与HAML相关的问题,我们将使用该版本:

    gem 'haml', '3.0.2'
    
        2
  •  2
  •   David Henner    14 年前

    将分页现在位于以下位置:
    gem'will_paginate',:git=>'git://github.com/mislav/will_paginate.git',:branch=>“rails3”

    更新您的gemfile

        3
  •  1
  •   Sam å±±    15 年前

    我相信原因是rails3逃避html的方式,不管是什么原因 will_pagiante 正在逃走。

    要解决这个问题,首先需要获得正确的gem,因为插件不起作用,所以添加 gem 'agnostic-will_paginate', :require => 'will_paginate' 这是在rails3项目的app文件夹中的新gem文件中完成的。

    在那之后,你需要阻止rails逃逸 raw 所以有点像 <%=raw will_paginate @products %> 这是反对 <%=h will_paginate @products %> 在铁路3中等于 <%= will_paginate @products %>

        4
  •  0
  •   Salil    15 年前

    将分页移到github。此存储库不再更新。 建议您安装gem而不是rails插件:

    gem install will_paginate
    

    再试一次