will_paginate未定义的方法. Will_paginate宝石似乎可以工作 [英] 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. =\
现在,我刚刚开始使用捆绑器,在捆绑器之前,所有东西一直都在工作. 在我的环境中.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宝石似乎可以工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!