Tag: 将分页

rails pagination – 后续页面中的不同per_page值第1页

我有一个博客/维基应用程序,我希望主页包含欢迎/登陆消息和5个最新的博客条目和链接到旧条目的分页。 例如,是否可以将5页作为分页搜索结果的第1页返回,将15页作为后续页面返回? 我目前正在使用will_paginate。

在rails中的will_paginate的page_entries_info中提供自定义消息

我是铁杆新手。 我想为page_entries_info显示我的自定义消息。 我已经通过以下链接但不能理解。 任何人都可以详细解释。 怎么办-I-指定定制-措辞-IN-A-意志PAGINATE视辅助

如何以这种方式对太阳黑子进行分页?

我有以下模型关联: class Product < ActiveRecord::Base has_many :prices class Price < ActiveRecord::Base belongs_to :product 这是我的控制器 class SearchController 5, :page => params[:page]) end @products = @search.results end end 然后我的看法: 假设我有10个产品,每个产品有20种不同的价格。 我的目标是每页显示5个产品,但如果页面上的价格数量一次超过25个,则价格会运行到下一页。 以下是我希望它做的两个不同的例子: Product 1, 2, 3, 4 + 5 Prices each = same page Product 5 + 6 Prices = this Product with Prices on next page […]

在将具有参数的范围应用于模型时使用will_paginate

我正在尝试创建一个搜索框,可用于按名称搜索用户。 我遇到的问题是我也想使用will_paginate gem。 这行代码@users = User.name(params[:name]).paginate(page: params[:page]) if params[:name].present? 是我认为问题所在。 class UsersController < ApplicationController def index @users = User.all.paginate(page: params[:page]) @users = User.name(params[:name]).paginate(page: params[:page]) if params[:name].present? end class User (name) { where(“name ILIKE ?”, “%#{name}%”)} end users/index.html.erb “Search by name” %>

模型上的Rails .page调用也调用count

试着做一个简单的Model.all.page(1) 但是每当调用.page时,它都会创建一个SQL COUNT调用。 (我的实际代码比上面的代码更复杂,但为了便于阅读而简化了。)有没有办法阻止.page调用SQL计数? 我正在处理数以百万计的产品,这个调用正在使页面刷新需要额外的2秒钟来加载。 我已经有自己的自定义计数,这是即时的所以我不需要这个.page计数。 编辑:默认不使用.all。 不好的例子抱歉。 下面是一个非常简单的例子,简单来说就是我的代码: Product.limit(1).page(1) 用我的真实代码SQL产生: (1495.3ms) SELECT COUNT(*) FROM ‘products’ LEFT OUTER JOIN… 我加入了产品表,我不需要计算,因此事实上我有自己的计数方法,我想使用它并且不需要.page来生成它自己的计数。

如何建立分页url​​的路径?

当用户#1喜欢/评论用户#2时,用户#2会收到通知: 通知/ _notifications.html.erb commented on 但是在用户#2点击通知后,由于我删除了activity_path ,因此它没有任何结果,如果我之前将其放回(notification.activity_id)我们会收到错误: 没有路由匹配{:action =>“show”,:controller =>“activities”,>:id => nil}缺少必需的键:[:id] 我不知道这是否可行,但点击通知用户#2将被带到活动的分页页面 。 通过gem will_paginate每页有20个活动,因此如果被注释的活动在第2页上,那么在点击活动时,用户#2应该被定向到:http: //0.0.0.0 : gem will_paginate /activities?page = 2 这至少会缩小注释对用户的活动供稿的位置。 活动/ index.html.erb activity.id), class: “btn”, method: :post do %> Like activities_controller.rb class ActivitiesController params[:page], :per_page => 20) end def show redirect_to(:back) end end 如果您发现可以这样做,请告诉我您是否需要更多代码:) UPDATE class NotificationsController < ApplicationController def index […]

Rails教程第10.3.3章 – 4 RSpec错误(应用程序工作)

我得到4个RSpec错误与Will-Paginategem有关,但对于我的生活,我无法弄清楚他们指的是什么。 该应用程序工作正常。 Failures: 1) UsersController GET ‘index’ for signed-in users should be successful Failure/Error: get :index NoMethodError: undefined method `paginate’ for # # ./app/controllers/users_controller.rb:7:in `index’ # ./spec/controllers/users_controller_spec.rb:30:in `block (4 levels) in ‘ 2) UsersController GET ‘index’ for signed-in users should have the right title Failure/Error: get :index NoMethodError: undefined method `paginate’ for # # ./app/controllers/users_controller.rb:7:in […]

will_paginate:如何构建“下一页”链接?

我知道这一定非常简单,但环顾四周后我找不到答案。 我正在使用will_paginate插件,我喜欢有一个简单的“下一页”链接,而不是整个will_paginate链接集合。 我怎样才能做到这一点? 谢谢!

在Rails 3问题中的Paginate

我目前正在研究一个我在Rails 2中编写的Reddit克隆应用程序,我正试图通过Rails 3中的新function加快速度。应用程序非常简单,它有一个Links scaffold,它有:url , :description , :points和:created_at 。 该应用程序路由到links#submissions ,您可以在其中查看所有提交的链接并提交新链接。 在提交页面上显示链接时,我在Rails 2中遇到了paginate方法的问题。 我目前正在运行Rails 3.2.3并且我理解我需要在Rails 3中使用gem will_paginate (我已经包含在我的Gemfile )但是每当我尝试拉出localhost:3000我都会收到以下错误消息: NoMethodError in LinksController#submissions… undefined method paginate for # 特别是在Links控制器的第90行。 这是我在LinksController.rb中的内容 (第90-93行)。 @link_pages, @Links = paginate :links, :order => order, :per_page => 20 @header_text = case ordering when ‘hot’ then ‘Top rated submissions’ when ‘new’ then ‘Latest […]

生产中的will_paginate错误NoMethodError(的未定义方法`page’:ActiveRecord :: Relation):

我正在使用will_paginate gem进行类似ajax的“see-more”链接。 它在开发中工作但在生产中失败。 在我的生产日志中,我得到: NoMethodError (undefined method `page’ for []:ActiveRecord::Relation): 我试过,在生产应用程序的根目录中键入: grep will_paginate Gemfile.lock 得到: will_paginate (3.0.4) will_paginate cap bundle:安装不会在我的VPS上安装will_paginate失败,但是当我试图明确要求’will_paginate’时,钢铁在开发中工作并且在生产中失败,但这次是整个站点,不仅仅是我使用过的行动will_paginate。 这需要在unicorn.log中触发错误: No such file to load will_paginate (LoadError) 所以我认为will_paginate不会在我的VPS上正确安装他的目录和捆绑安装,但为什么呢? 我试着输入: gem list 那里没有will_paginate。 所以我明确地说,在我当前的应用程序目录中。 gem install will_paginate,但也没有解决问题。 所以我gem卸载will_paginate和“帽子部署”后我再次gem列表再次在那里没有will_paginate 的Gemfile: gem ‘rails’, ‘3.2.13’ gem ‘pg’ gem ‘will_paginate’ gem ‘sass-rails’ gem ‘jquery-rails’ gem ‘jquery-ui-rails’ gem ‘devise’ gem […]