未定义的方法 `will_paginate',Rails 3.1/DataMapper [英] undefined method `will_paginate', Rails 3.1 / DataMapper

查看:55
本文介绍了未定义的方法 `will_paginate',Rails 3.1/DataMapper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新安装的 will_paginate 3.0.0

Newly installed 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 分页.

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>

所以 will_paginate 有效,但视图助手无效.我错过了什么吗?如果这有什么不同,我正在使用纤薄的模板.我缺少一些语法更改吗?文档很简单,但在这一点上没有帮助.我查看了来源,似乎没有任何变化,但我无法弄清楚为什么它无法访问

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')

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

解决方案:

宝石文件:

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

初始化器:

require 'will_paginate'
require 'will_paginate/data_mapper'

它出现了,但如果不是在模板的顶部,我会得到一个

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

堆栈层太深

错误我无法解释

推荐答案

不要在 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',Rails 3.1/DataMapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆