如何正确安装Kaminari?

发布于 2024-11-26 01:39:27 字数 626 浏览 2 评论 0原文

我在如何让 Kaminari 工作上遇到了一些问题。我在GitHub上完成了安装过程。

gem "kaminari"

然后运行

bundle

我有这个索引片段

@users = User.order("name")

我在我的视图中添加了这个

<%= paginate @users %>

然后我得到了这个错误。

undefined method `paginate' for #<#<Class:0x00000102934330>:0x00000102932508>

我错过了什么吗?我还尝试包含页面方法

@users = User.order("id").page(1)

但我收到此错误

undefined method `page' for #<ActiveRecord::Relation:0x000001017d0300>

I'm having a bit problem on how to get Kaminari work. I did the installation procedure in GitHub.

gem "kaminari"

Then run

bundle

I have this snippet for index

@users = User.order("name")

I added this on my view

<%= paginate @users %>

Then I got this error.

undefined method `paginate' for #<#<Class:0x00000102934330>:0x00000102932508>

Did I missed something? I also tried to include the page method

@users = User.order("id").page(1)

But I get this error instead

undefined method `page' for #<ActiveRecord::Relation:0x000001017d0300>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

好菇凉咱不稀罕他 2024-12-03 01:39:28

看看 kaminari 的railscast
真的很好
http://railscasts.com/episodes/254-pagination-with-kaminari

bash< /强>
Rails g kaminari:views 默认

products_controller.rb

@products = Product.order("name").page(params[:page]).per(5)

products/index.html.erb

<%= paginate @products %>

app/views/kaminari/_prev_span.html.erb

<span class="prev disabled"><%= raw(t 'views.pagination.previous') %></span>

take a look at the railscast for kaminari
its really nice
http://railscasts.com/episodes/254-pagination-with-kaminari

bash
rails g kaminari:views default

products_controller.rb

@products = Product.order("name").page(params[:page]).per(5)

products/index.html.erb

<%= paginate @products %>

app/views/kaminari/_prev_span.html.erb

<span class="prev disabled"><%= raw(t 'views.pagination.previous') %></span>
漆黑的白昼 2024-12-03 01:39:27

在项目 Gemfile 中包含 kaminaribootstrap-kaminari-views gem,

gem "kaminari"

gem "bootstrap-kaminari-views"

在终端中执行捆绑安装

$ bundle install

在 products_controller.rb 中,

@products = Product.order("name")

@products = Kaminari.paginate_array(@products).page(params[:page]).per(5)

在 products/index.html.erb,<%= 分页@products, :theme => 'twitter-bootstrap-3' %>;

include kaminari and bootstrap-kaminari-views gems in your project Gemfile,

gem "kaminari"

gem "bootstrap-kaminari-views"

Execute bundle install in terminal,

$ bundle install

In products_controller.rb,

@products = Product.order("name")

@products = Kaminari.paginate_array(@products).page(params[:page]).per(5)

In products/index.html.erb,<%= paginate @products, :theme => 'twitter-bootstrap-3' %>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文