DavyJonesLocker / client_side_validations-simple_form

Simple Form plugin for ClientSideValidations
MIT License
254 stars 102 forks source link

Rails engine generator and loading issues #50

Closed patricklindsay closed 3 years ago

patricklindsay commented 8 years ago

When running the generator inside an engine I get the following message

 bundle exec rails g client_side_validations:install
[WARNING] Could not load generator "generators/client_side_validations/install_generator". Error: undefined method `config' for nil:NilClass.
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.5.1/lib/rails.rb:44:in `configuration'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/client_side_validations-4.2.1/lib/generators/client_side_validations/copy_assets_generator.rb:14:in `asset_directory'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/client_side_validations-4.2.1/lib/generators/client_side_validations/copy_assets_generator.rb:34:in `installation_message'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/client_side_validations-4.2.1/lib/generators/client_side_validations/copy_assets_generator.rb:37:in `<class:CopyAssetsGenerator>'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/client_side_validations-4.2.1/lib/generators/client_side_validations/copy_assets_generator.rb:3:in `<module:Generators>'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/client_side_validations-4.2.1/lib/generators/client_side_validations/copy_assets_generator.rb:2:in `<module:ClientSideValidations>'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/client_side_validations-4.2.1/lib/generators/client_side_validations/copy_assets_generator.rb:1:in `<top (required)>'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/client_side_validations-4.2.1/lib/generators/client_side_validations/install_generator.rb:1:in `<top (required)>'

Seems like this is blowing up here because a Rails application doesn't exist. A workaround I found was to return early from the installation_message method.

Now the issue I'm having (which is why I'm posting in this repo) is that I can't seem to load client_side_validations-simple_form gem from the engine. I've added it as a dependency in the gemspec and tried to require it within the Engine.

module MyEngine
  class Engine < ::Rails::Engine
    require 'simple_form'
    require 'client_side_validations'
    require 'client_side_validations-simple_form'

    isolate_namespace MyEngine

  end
end
rails g client_side_validations:copy_assets
/Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- client_side_validations-simple_form (LoadError)
    from /Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `block in require'
    from /Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:240:in `load_dependency'
    from /Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5.1/lib/active_support/dependencies.rb:274:in `require'
    from /Users/patrick/dev/integral/lib/integral/engine.rb:6:in `<class:Engine>'
    from /Users/patrick/dev/integral/lib/integral/engine.rb:2:in `<module:Integral>'
    from /Users/patrick/dev/integral/lib/integral/engine.rb:1:in `<top (required)>'
    from /Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.5.1/lib/rails/engine/commands.rb:11:in `require'
    from /Users/patrick/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/railties-4.2.5.1/lib/rails/engine/commands.rb:11:in `<top (required)>'
Using rails 4.2.5.1
Using client_side_validations 4.2.1
Using client_side_validations-simple_form 3.2.1
Using simple_form 3.2.1

Thanks in advance!

tagliala commented 8 years ago

PR are welcome

tagliala commented 8 years ago

btw you should require client_side_validations-simple_form as

require 'client_side_validations/simple_form'
patricklindsay commented 8 years ago

I'm not familiar with the code, I would just hard code the asset_directory method to return app/assets/javascripts but not sure if this is the right approach.

Cool thanks that resolved my second issue :)

tagliala commented 3 years ago

I don't know if this is still an issue, but I'm going to close here