未定义方法“will_paginate”,Rails 3.1 / DataMapper

发布于 2024-12-04 16:42:39 字数 1301 浏览 0 评论 0原文

新安装的 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)

如果我输入 ?page=X (其中 x 是 url 中的页码),它将提取用户的所有票证并以 5 为单位进行分页。

=will_paginate(@tickets) 

在视图中不起作用,这会导致

undefined method `will_paginate' for #<#<Class:0x000000053674c8>:0x0000000535cd48>

所以 will_paginate 起作用,但视图助手不起作用。我错过了什么吗?如果这有什么区别的话,我正在使用 slim 模板。我缺少一些语法更改吗?该文档很简单,但除此之外没有任何帮助。我查看了源代码,似乎没有任何变化,但我无法弄清楚为什么它无法访问

然后切线,这与关联混乱。

=> @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', '~> 3.0.0'       # removed this, :require=>'will_paginate/data_mapper'

初始化程序:

require 'will_paginate'
require 'will_paginate/data_mapper'

它显示出来,但如果不在模板的顶部,我会收到

堆栈级别太深的

错误,我无法解释

Newly installed will_paginate 3.0.0

gem 'will_paginate', '~> 3.0.0', :require=>'will_paginate/data_mapper'

Running a controller query:

@tickets = Ticket.paginate(:page => params[:page], :per_page => 5,:username => @ticket.username)

Which works, pulls up all the tickets for a user and paginates in 5's if I put ?page=X where x is a page number in the url.

=will_paginate(@tickets) 

in the view does not work, this results in

undefined method `will_paginate' for #<#<Class:0x000000053674c8>:0x0000000535cd48>

So will_paginate works, but not the view helper. Am I missing something? I'm using slim templating if that makes any difference. Is there some syntax change I'm missing? The documentation is simple but unhelpful beyond this point. I looked into the source, and there does not seem to be any changes, but I cannot figure why it is inaccessible

And then on tangent, this messes with an association.

=> @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

SOLUTION:

gemfile:

gem 'will_paginate', '~> 3.0.0'       # removed this, :require=>'will_paginate/data_mapper'

intializer:

require 'will_paginate'
require 'will_paginate/data_mapper'

It shows up, but if not at the top of the template, I get a

stack level too deep

error I am unable to interpret

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

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

发布评论

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

评论(3

守不住的情 2024-12-11 16:42:40
gem 'will_paginate', '~> 3.0.0', require: %w[
  will_paginate
  will_paginate/data_mapper
]
gem 'will_paginate', '~> 3.0.0', require: %w[
  will_paginate
  will_paginate/data_mapper
]
裸钻 2024-12-11 16:42:39

正如您已经发现的那样,不要在 Gemfile 中使用 :require 选项;相反,在 config/application.rb 中的某处需要“will_paginate/data_mapper”,例如在 Bundler 设置之后。

Don't use the :require option in the Gemfile, as you already figured out; instead require "will_paginate/data_mapper" somewhere in config/application.rb, for instance after the Bundler setup.

愿与i 2024-12-11 16:42:39

有一个类似的问题,其答案表明这里的自动要求是问题所在。请参阅 will_paginate 未定义方法。 Will_paginate gem 似乎可以用于问题和答案

There is a similar question with an answer that indicates that auto-requiring here is the problem. See will_paginate undefined method. The Will_paginate gem appears to work though for the question and answer.

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