will_paginate 未定义的方法.Will_paginate gem 似乎可以工作 [英] will_paginate undefined method. The Will_paginate gem appears to work though
问题描述
我使用的是 rails 2.3.8
I'm using rails 2.3.8
我的错误:
undefined method `will_paginate' for #<ActionView::Base:0x1124bfa10>
在 environment.rb 中:
in environment.rb:
require "bundler/setup"
Bundler.require(:default)
在我的 Gemfile 中:
in my Gemfile:
gem "will_paginate", "2.3.14"
在视图中:
<%= will_paginate(@subscriptions) %>
在控制器中:
@search = Subscription.search(params[:search])
@search.order ||= :ascend_by_account_id
@subscriptions = @search.all.paginate(:include => :account, :page => params[:page], :per_page => 30)
现在...将分页方法似乎在应用程序的其余部分工作...只是这个应该包含分页链接的 will_paginate 方法不起作用.=
Now... will paginate methods appear to work in the rest of the app... it's just that this will_paginate method that is supposed to include pagination links doesn't work. =
现在,我刚开始使用 bundler,在 bundler 之前,一切都正常.在我的环境中.rb 我愿意
Now, I just started using bundler, and before bundler, everything worked all the time. in my environment.rb I do
require "bundler/setup"
Bundler.require(:default)
就在 Rails::Initializer
调用之前
这里是我的 gem 文件的 :default 部分:
and here is the :default part of my gem file:
source "http://rubygems.org"
# system
gem "rails", "2.3.8"
gem "activesupport", "2.3.8", :require => "active_support"
gem "rake", "0.8.7"
# might be for POW, not sure
gem "childprocess", "0.2.2", :git => "git://github.com/jarib/childprocess.git"
# app
gem "mysql", "2.7"
gem "lockfile"
gem "ssl_requirement", "0.1.0"
gem "attr_encrypted", "1.1.2"
#gem "searchlogic", "2.5.6"
gem "will_paginate", "2.3.16"
gem "paperclip"
gem "garb", "0.7.6"
gem "delayed_job", "2.0.3"
gem "httparty", "0.5.2"
gem "pony", "1.1"
gem "friendly_id", "3.0.6"
gem "stringex", "1.1.0"
gem "i18n", "0.4.2"
gem "sms_fu", "1.1.1"
注意:由于某种原因,搜索逻辑仅在以经典 rails 2.3 方式包含在 Rails:Initializer.run 调用中时才有效., config.gem "searchlogic", :version => "2.2.28"
NOTE: for some reason search logic only works when it's included in the Rails:Initializer.run call in classic rails 2.3 way., config.gem "searchlogic", :version => "2.2.28"
推荐答案
禁用 will_paginate 的自动要求:
Disable the auto-requiring of will_paginate:
# Gemfile
gem "will_paginate", "~> 2.3.15", :require => nil
并在 environment.rb 的末尾手动要求它:
And require it yourself, manually, at the end of environment.rb:
# end of environment.rb
require "will_paginate"
问题是,如果您在 Rails::Initializer
调用之前需要 will_paginate,它可能无法正确提升.
The thing is, if you require will_paginate before the Rails::Initializer
call, it might not boostrap properly.
这篇关于will_paginate 未定义的方法.Will_paginate gem 似乎可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!