Rails 4 升级的 Formtastic Gem 问题

Formtastic Gem issues with Rails 4 upgrade

将应用程序从 Rails 3.2 升级到 Rails 4.2.8 时,ruby 版本保持不变,仍为 2.3.2。捆绑包安装和捆绑包更新 运行 成功,没有警告或错误。

环境: windows, ruby 2.3.2

执行任何 rake 任务或开始服务器中断,发现以下错误,

抽取任务中断:

  Error:[rake --tasks] C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-1.1.9/lib/cucumber/ast/feature_element.rb:52: warning: circular argument reference - name
  rake aborted!
  LoadError: cannot load such file -- formtastic/helpers/buttons_helper
  C:/workspace/project1/lib/ext/gems/formtastic/formtastic.rb:13:in `<module:Formtastic>'
  C:/workspace/project1/lib/ext/gems/formtastic/formtastic.rb:1:in `<top (required)>'
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'

开发服务器启动抛出错误:

C:/workspace/project1/lib/ext/gems/formtastic/formtastic.rb:13:in `<module:Formtastic>': cannot load such file -- formtastic/helpers/buttons_helper (LoadError)
  from C:/workspace/projects/CosmoD2Upgrade/director2/lib/ext/gems/formtastic/formtastic.rb:1:in `<top (required)>'
  from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `block in require'
  from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency'

宝石文件:

   # form builder
   gem 'formtastic'

Gemfile.lock

formtastic (3.1.5)
  actionpack (>= 3.2.13)

我尝试了多个版本的 Formtastic gem,即使降到 2.0 版本也无法解决问题。让我知道是否有可用的补丁或修复程序。

更新:包括 rake 失败的错误堆栈跟踪

Error:[rake --tasks] C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/cucumber-1.1.9/lib/cucumber/ast/feature_element.rb:52: warning: circular argument reference - name
    rake aborted!
    LoadError: cannot load such file -- formtastic/helpers/buttons_helper
    C:/workspace/project/lib/ext/gems/formtastic/formtastic.rb:13:in `<module:Formtastic>'
    C:/workspace/project/lib/ext/gems/formtastic/formtastic.rb:1:in `<top (required)>'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `block in require'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `require'
    C:/workspace/project/config/application.rb:9:in `block in <top (required)>'
    C:/workspace/project/config/application.rb:9:in `each'
    C:/workspace/project/config/application.rb:9:in `<top (required)>'
    C:/workspace/project/Rakefile:4:in `require'
    C:/workspace/project2/Rakefile:4:in `<top (required)>'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/rake_module.rb:28:in `load'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/rake_module.rb:28:in `load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:686:in `raw_load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:96:in `block in load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:95:in `load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:79:in `block in run'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
    C:/workspace/project/bin/rake:4:in `<main>'
    Polyglot::PolyglotLoadError: Failed to load C:/workspace/project/lib/ext/gems/formtastic/formtastic.rb using extensions rb, treetop, tt
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:55:in `load'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:68:in `rescue in require'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `block in require'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:240:in `load_dependency'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-4.2.8/lib/active_support/dependencies.rb:274:in `require'
    C:/workspace/project/config/application.rb:9:in `block in <top (required)>'
    C:/workspace/project/config/application.rb:9:in `each'
    C:/workspace/project/config/application.rb:9:in `<top (required)>'
    C:/workspace/project/Rakefile:4:in `require'
    C:/workspace/project/Rakefile:4:in `<top (required)>'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/rake_module.rb:28:in `load'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/rake_module.rb:28:in `load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:686:in `raw_load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:96:in `block in load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:95:in `load_rakefile'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:79:in `block in run'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:178:in `standard_exception_handling'
    C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-11.3.0/lib/rake/application.rb:77:in `run'
    C:/workspace/projects/bin/rake:4:in `<main>'

错误指向以下文件和 buttonhelper 调用。

    .....  
    Line no 13:
    module Helpers::ButtonsHelper
      def commit_button(*args)
        options = args.extract_options!
        text = options.delete(:label) || args.shift

        text = (localized_string(commit_button_i18n_key, text, :action, :model => commit_button_object_name) ||
            Formtastic::I18n.t(commit_button_i18n_key, :model => commit_button_object_name)) unless text.is_a?(::String)

        button_html = options.delete(:button_html) || {}
        button_html.merge!(:class => [button_html[:class], commit_button_i18n_key].compact.join(' '))

        wrapper_html = options.delete(:wrapper_html) || {}
        wrapper_html[:class] = (commit_button_wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')

        accesskey = (options.delete(:accesskey) || default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
        button_html = button_html.merge(:accesskey => accesskey) if accesskey

        Formtastic::Util.html_safe(submit(text, button_html))
      end
    end
    .....

您似乎使用了 formtasticformtastic-bootstrap gem。不幸的是 formtastic-bootstrap 与当前的 formtastic 版本不兼容,而且它似乎没有维护,因为它在过去两年中没有收到任何更新。

我看到两个选项:

  1. 降级到 formtastic ~> 2.1.1,如 this answer 中所述。
  2. 替换或分叉并修复 formtastic-bootstrap 以便能够向前移动。

我会选择第二个选项。仅仅因为它依赖于 gem(似乎无论如何都被放弃了)而使用旧的软件堆栈对我来说听起来不是一个好计划。