【问题标题】:undefined method `eager_load' when upgrading to formtastic 3.1升级到formtastic 3.1时未定义的方法“eager_load”
【发布时间】:2015-03-18 05:15:31
【问题描述】:

我在这个项目中使用 Ruby 1.9.3 和 Rails 3.2.17。我计划升级到 Rails 4,但遇到了很多 gem 不兼容的问题,所以我首先尝试更新一些 gem。 我正在将 formtastic 从 2.0.2 更新到 3.1.3。

我看到很多这样的弃用警告:

DEPRECATION WARNING: input_class is deprecated and will be removed from Formtastic 4.0 (configure Formtastic::FormBuilder.input_class_finder instead (upgrade guide on wiki: http://bit.ly/1F9QtKc )). (called from _app_views_prescriptions__fields_html_haml___278490936240938991_103076320 at /home/hegwin/Workspace/rails_projects/pharmmd/app/views/prescriptions/_fields.html.haml:7)

我关注了formtastic wiki Upgrading to Formtastic 3.1,并将这两行添加到config/initializers/formtastic.rb

Formtastic::FormBuilder.action_class_finder = Formtastic::ActionClassFinder
Formtastic::FormBuilder.input_class_finder = Formtastic::InputClassFinder

之后,当我尝试运行 rspec 时,它抛出了一个错误:

NoMethodError: undefined method `eager_load' for #<Rails::Application::Configuration:0x00000006306a50>

/home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/railtie/configuration.rb:85:in `method_missing': undefined method `eager_load' for #<Rails::Application::Configuration:0x00000006459b50> (NoMethodError) from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:32:in `use_const_defined?' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:69:in `<class:NamespacedClassFinder>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:24:in `<module:Formtastic>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/formtastic-3.1.3/lib/formtastic/namespaced_class_finder.rb:1:in `<top (required)>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/formtastic-3.1.3/lib/formtastic/action_class_finder.rb:7:in `<module:Formtastic>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/formtastic-3.1.3/lib/formtastic/action_class_finder.rb:1:in `<top (required)>' from /home/hegwin/Workspace/rails_projects/pharmmd/config/initializers/formtastic.rb:104:in `<top (required)>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:50:in `load' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:50:in `load' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/zeus-0.13.3/lib/zeus/load_tracking.rb:43:in `load' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `block in load' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:236:in `load_dependency' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/activesupport-3.2.17/lib/active_support/dependencies.rb:245:in `load' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/engine.rb:593:in `block (2 levels) in <class:Engine>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/engine.rb:592:in `each' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/engine.rb:592:in `block in <class:Engine>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `instance_exec' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/initializable.rb:30:in `run' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/initializable.rb:55:in `block in run_initializers' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `each' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/initializable.rb:54:in `run_initializers' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/application.rb:136:in `initialize!' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/railties-3.2.17/lib/rails/railtie/configurable.rb:30:in `method_missing' from /home/hegwin/Workspace/rails_projects/pharmmd/config/environment.rb:5:in `<top (required)>' from /home/hegwin/Workspace/rails_projects/pharmmd/spec/spec_helper.rb:12:in `require' from /home/hegwin/Workspace/rails_projects/pharmmd/spec/spec_helper.rb:12:in `<top (required)>' from /home/hegwin/Workspace/rails_projects/pharmmd/spec/features/patient_edit_medication.feature:1:in `require' from /home/hegwin/Workspace/rails_projects/pharmmd/spec/features/patient_edit_medication.feature:1:in `<top (required)>' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run' from /home/hegwin/.rvm/gems/ruby-1.9.3-p362@medpro/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'

【问题讨论】:

  • 我遇到了同样的问题。非常感谢您的帮助。
  • 我遇到了同样的问题。我正在使用 rails 5.0.0.1、ruby 2.2.4 和 formtastic 3.1.4。我关注了 formtastic wiki - github.com/justinfrench/formtastic/wiki/… 并且它的作品完美。通过将 rails 升级到最低 4.0.0 并将 ruby​​ 升级到最低 2.0.0 来试一试,它可能会起作用。希望对你有帮助!

标签: ruby-on-rails formtastic


【解决方案1】:

formtastic 团队已知此问题。有关详细信息,请参阅问题 #1137 和 #1135。简而言之,权宜之计是利用分叉的 issue_1135 分支。这是 Gemfile 行:

gem 'formtastic', :git => 'git://github.com/sepastian/formtastic.git', :branch => 'issue_1135'

更好的办法是派生该分支以创建您自己的存储库。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 2015-01-26
    • 2023-04-03
    • 2014-07-15
    • 2017-06-10
    • 1970-01-01
    相关资源
    最近更新 更多