Missing helper file (LoadError) #4737

Closed
OliverLetterer opened this Issue Jan 28, 2012 · 8 comments

Projects

None yet

3 participants

@OliverLetterer

If i create a new mountable engine with

rails plugin new some-3.1-plugin_version --mountable

and try to run rake from terminal, I always get the following error messages:

/Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:317:in `rescue in depend_on': Missing helper file helpers/some_3.1_plugin_version/application_helper.rb (LoadError)
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:312:in `depend_on'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/actionpack-3.2.1/lib/abstract_controller/helpers.rb:135:in `block in modules_for_helpers'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/actionpack-3.2.1/lib/abstract_controller/helpers.rb:131:in `map!'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/actionpack-3.2.1/lib/abstract_controller/helpers.rb:131:in `modules_for_helpers'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/actionpack-3.2.1/lib/action_controller/metal/helpers.rb:92:in `modules_for_helpers'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/actionpack-3.2.1/lib/abstract_controller/helpers.rb:95:in `helper'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/actionpack-3.2.1/lib/action_controller/railties/paths.rb:18:in `block (2 levels) in with'
    from /Users/oliver/Development/ebf/rails/temp/some-3.1-plugin_version/app/controllers/some-3.1-plugin_version/application_controller.rb:2:in `<module:Some31PluginVersion>'
    from /Users/oliver/Development/ebf/rails/temp/some-3.1-plugin_version/app/controllers/some-3.1-plugin_version/application_controller.rb:1:in `<top (required)>'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:359:in `require_or_load'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:313:in `depend_on'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:225:in `require_dependency'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/engine.rb:438:in `each'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/engine.rb:438:in `block in eager_load!'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/engine.rb:436:in `each'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/engine.rb:436:in `eager_load!'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/application/railties.rb:8:in `each'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/application/railties.rb:8:in `all'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/engine.rb:434:in `eager_load!'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `instance_exec'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/initializable.rb:30:in `run'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `each'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/initializable.rb:54:in `run_initializers'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/application.rb:136:in `initialize!'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/oliver/Development/ebf/rails/temp/some-3.1-plugin_version/test/dummy/config/environment.rb:5:in `<top (required)>'
    from /Users/oliver/Development/ebf/rails/temp/some-3.1-plugin_version/test/test_helper.rb:4:in `require'
    from /Users/oliver/Development/ebf/rails/temp/some-3.1-plugin_version/test/test_helper.rb:4:in `<top (required)>'
    from /Users/oliver/Development/ebf/rails/temp/some-3.1-plugin_version/test/integration/navigation_test.rb:1:in `require'
    from /Users/oliver/Development/ebf/rails/temp/some-3.1-plugin_version/test/integration/navigation_test.rb:1:in `<top (required)>'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/oliver/.rvm/gems/ruby-1.9.3-p0@connector.server/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [/Users/oliver/.rvm/rubies/ruby-1.9.3-p0/bi...]

Tasks: TOP => default => test
(See full trace by running task with --trace)

I guess the most important part is Missing helper file helpers/some_3.1_plugin_version/application_helper.rb (LoadError) which looks like the folder is not named correctly. The generator created the folder some-3.1-plugin_version. Im running rails 3.2.1 and ruby 1.9.3-p0. Im not sure if Im not supposed to use - in rails application names.

@kennyj

I can reproduce this problem. The argument is underscorized in the following line.

https://github.com/rails/rails/blob/master/actionpack/lib/abstract_controller/helpers.rb#L134

"-" is converted to "_" by underscore method.

ruby-1.9.3-p0 :001 > "abd-def.ghi".underscore
 => "abd_def.ghi"

If we don't call underscore method, we have an another problem.
I also found the follwing line.

https://github.com/rails/rails/blob/master/actionpack/lib/abstract_controller/helpers.rb#L136

The file_name is camelized. "-" is not converted by camelize method.

ruby-1.9.3-p0 :003 > "abc-def".camelize
 => "Abc-def"

It seems that we can not use "-" and "." (and so on...) in engine names.
only /[0-9a-zA-Z_]+/ ?

@kennyj

I think that the cause of the problem is difference of concept for underscore and camelize.

In actionpack/lib/abstract_controller/helpers.rb

...
          when String, Symbol
            file_name = "#{arg.to_s.underscore}_helper"
            require_dependency(file_name, "Missing helper file helpers/%s.rb")
            file_name.camelize.constantize
          when Module
...

I think that arg don't be permitted the directory/file name which include "-" and ".".

In railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb

...
      def name
        @name ||= begin
          # same as ActiveSupport::Inflector#underscore except not replacing '-'
          underscored = original_name.dup
          underscored.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
          underscored.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
          underscored.downcase!

          underscored
        end
      end

      def camelized
        @camelized ||= name.gsub(/\W/, '_').squeeze('_').camelize
      end
...

If we modify helpers.rb, we should do the fixing like an above Plan 1.
If we modify plugin_new_generator.rb, we should do the fixing like an above Plan 2.
(or mixed ?)

What do you think?
I think that we should use Plan 2 :-)

@OliverLetterer

I would be perfectly fine with 2 :)

@dmitriy-kiriyenko

Plan 2 seems great for me.

@kennyj

@OliverLetterer @dmitriy-kiriyenko Thanks !!

To resolve this issue, I think that we need to change the specification.
I'll talk about this issue to Rails Core Team tonight (+9 JST) :-)

@kennyj

I sent pull request. #4826.
I use Plan 2 !

@kennyj

I'm closing this issue, because the PR is merged.
Everyone thanks!

@kennyj kennyj closed this Feb 1, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment