未定义方法“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)
如果我输入 ?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如您已经发现的那样,不要在 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.
有一个类似的问题,其答案表明这里的自动要求是问题所在。请参阅 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.