Tag: 将分页

undefined方法`will_paginate’,Rails 3.1 / DataMapper

新安装的will_paginate 3.0.0 gem ‘will_paginate’, ‘~> 3.0.0′, :require=>’will_paginate/data_mapper’ 运行控制器查询: @tickets = Ticket.paginate(:page => params[:page], :per_page => 5,:username => @ticket.username) 哪个有效,如果我放了?页面= X,其中x是url中的页码,则为5个用户提取所有门票和分页。 =will_paginate(@tickets) 在视图中不起作用,这导致了 undefined method `will_paginate’ for #<#:0x0000000535cd48> 所以will_paginate可行,但不是视图助手。 我错过了什么吗? 如果这有任何区别,我会使用纤细的模板。 我缺少一些语法变化吗? 文档很简单但超出了这一点无益。 我查看了源代码,似乎没有任何变化,但我无法理解为什么它无法访问 然后切线,这与关联混乱。 => @ instance.model_belonging_to_instance.create(:text =>’test’) TypeError: can’t convert nil into Integer from /home/qx/.rvm/gems/ruby-1.9.2-p180/gems/will_paginate-3.0.0/lib/will_paginate/page_number.rb:16:in `Integer’ etc etc et al 解: 的Gemfile: gem ‘will_paginate’, […]

获取will_paginate以在第一页上定义自定义偏移量

我正在我的rails网站上建立一个新闻栏目,它使用will_paginate进行分页。 现在我想知道如何用will_paginate为第一页指定自定义偏移量 。 像这样的东西: @featured_news = Post.first @news = Post.offset(1).paginate(:page => params[:page]) 我需要最新的新闻条目是特殊的,不包含在@news对象中。 我怎么能做到这一点? 谢谢你的时间!

will_paginate报告过多的条目和页面

我正在使用will_paginate来显示从包含连接和select语句的查询返回的数据。 当我对数据进行分页时,条目数等于执行select语句之前的条目数,即使在查询后调用了paginate,并且查询包含的元素少于分页报告。 @sales = Sale.joins(:line_items).where(company_id: company_id, status: [‘Complete’, ‘Voided’], time: (midnight_1..midnight_2)).order(‘id DESC’) puts @sales.length 14 @sales = @sales.select(‘distinct sales.*’) puts @sales.length 4 @sales.paginate(:per_page => 4, :page => params[page]) puts @sales.total_entries 14 这导致显示指向空白页面的链接。

Rails将_paginate自定义路由

如何将will_paginate与自定义路由一起使用? 我的路线中有以下内容: map.connect ‘human-readable/:name’, :controller => :tags, :action => ‘show’ 但是就我所知,will_paginate会使用url_for,但我想使用’human-readable’而不是url_for,但是怎么样? 编辑 当我点击will_paginate生成的分页链接时,它正在使用: “tags/show?name=Elektronikindustri&page=1” 代替: “/human-readable/show?name=Elektronikindustri&page=1” 我希望will_paginate使用我的自定义路由而不是实际的控制器名称

Will_paginate插件在同一页面上的两个对象上

您好我在同一页面上的两个对象上使用了will_paginte插件。 就像在stackoverflow上一样。 有一个个人资料页面上有两个问题和答案的分页。 我有问题,即: – 当用户点击问题分页页面2.答案页面也在更新。 原因是两者都发送了一个post变量ie params[:page] 如何更改此变量以便只更新一个变量。 以及如何维护该用户不应该丢失其他页面。 即 他是问题的第3页和答案的第1页,现在他点击问题的第5页,结果应该是问题的第3页和答案的第5页。

将will_paginate与多个模型一起使用(Rails)

很确定我在这里遗漏了一些非常简单的东西: 我正在尝试显示一系列包含两个不同模型实例的页面 – 配置文件和组。 我需要按名称属性排序。 我可以为每个模型选择所有实例,然后对它们进行排序和分页,但这感觉很邋and且效率低下。 我正在使用mislav-will_paginate,并想知道是否有更好的方法来实现这一目标? 就像是: [Profile, Group].paginate(…) 会是理想的!

Rails:使用带复杂关联的will_paginate查找

我在进行复杂的查找时遇到了will_paginate的问题。 :photo has_many :tags, :through => :tagships :item has_many :photos :photo belongs_to :item @photos = @item.photos.paginate :page => params[:page], :per_page => 200, :conditions => [ ‘tags.id IN (?)’, tag_ids], :order => ‘created_at DESC’, :joins => :tags, :group => “photos.id HAVING COUNT(DISTINCT tags.id) = #{tag_count}” 我想获取tag_ids数组中包含所有标签的所有照片。 MySQL的IN通常进行“或”搜索,但我需要“和”。 我发现如何修改IN以模仿“和”行为,并且在使用model.find()时它工作正常,只要获取的记录数低于my:per_page计数,它也可以工作。 但如果必须分页,生成的SQL类似于: SELECT count(*) AS count_all, photos.id HAVING COUNT(DISTINCT […]

在Rails中组合条件数组

我正在使用Rails3 beta,will_paginate gem和geokit gem&plugin。 作为geokit-rails插件,似乎不支持Rails3范围(包括:origin符号是问题),我需要使用.find语法。 代替范围,我需要以数组格式组合两组标准: 我有一个默认条件: conditions = [“invoices.cancelled = ? AND invoices.paid = ?”, false, false] 我可能需要将以下条件之一添加到默认条件,具体取决于UI选择: #aged 0 lambda {[“created_at IS NULL OR created_at = ? AND created_at 90 lamdba {[“created_at >= ?”, Date.today + 90.days]} 生成的查询类似于: @invoices = Invoice.find( :all, :conditions => conditions, :origin => ll #current_user’s lat/lng pair ).paginate(:per_page => […]

如何让paginate工作而不是重定向到’public / index.html’?

我的主页使用’public / index.html’,它覆盖了我在这里阅读的所有内容。 因此,我已将所有已登录的用户重定向到http://localhost:3000/home ,我将其定义为get ‘/home’ => ‘static_pages#home’, :as => :home in my路线 我面临的问题是,在登录用户(/ home)的主页上,有分页。 当我尝试点击第2页http://localhost:3000/?page=2 ,它会被发送到public / index.html。 我尝试了链接http://localhost:3000/home/?page=2作为测试,但它给了我一个空白的分页。 没有显示任何项目。 我怎样才能解决这个问题? 这是控制器 class StaticPagesController 1, :per_page => 10) else redirect_to root_path end end 然后在我看来 这是_item.html.erb部分 <li id="”> posted made a comment shared this 150, :omission=>’ …(continued)’) %>

Rails – will_paginate说“变量似乎是空的。 你忘了传递will_paginate的集合对象吗?“

我有这个问题: @cars = Car.paginate(page: params[:page], per_page: 5).order(created_at: :desc).group_by { |r| r.created_at.to_date } 并在视图中: = will_paginate @cars 但我收到此错误(在site#index呈现): The @site variable appears to be empty. Did you forget to pass the collection object for will_paginate? 我也试过这样更新查询: @cars = Car.order(created_at: :desc).paginate(page: params[:page], per_page: 5).group_by { |r| r.created_at.to_date } 但错误仍然是一样的。 如何解决这个问题? 谢谢