trailblazer / cells

View components for Ruby and Rails.
https://trailblazer.to/2.1/docs/cells.html
3.07k stars 236 forks source link

autoloading issues #350

Closed sdesbure closed 9 years ago

sdesbure commented 9 years ago

Hello, not sure if it's here but I give a try: I use cells (and trailblazer in general). In order to refactor, I've created a module reused in some cells: TypeIcon put in app/cells/type_icon.rb:

module Cell::TypeIcon
  private

  def type_icon
  end
end

I then include it in my concepts: for example in Application::Cellput in app/concepts/application/cell.rb:

class Application::Cell < Cell::Concept
  include AbstractController::Helpers
  include Monban::ControllerHelpers
  include Cell::TypeIcon

   def show
     render
   end
end

but when I start rails, I have the following error:

Users/sylvain/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:495:in `load_missing_constant': Unable to autoload constant TypeIcon, expected /Users/sylvain/Sources/EasyConnectPortal/app/cells/type_icon.rb to define it (LoadError)
    from /Users/sylvain/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/sylvain/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:526:in `load_missing_constant'
    from /Users/sylvain/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:184:in `const_missing'
    from /Users/sylvain/Sources/EasyConnectPortal/app/concepts/application/cell.rb:4:in `<class:Cell>'
    from /Users/sylvain/Sources/EasyConnectPortal/app/concepts/application/cell.rb:1:in `<top (required)>'

If I comment the line, start, uncomment, refresh, it works after another refresh (the first one whine about the missing constant but not the second one). Any hints to make it work?

thanks!

Tab10id commented 9 years ago

app/cells/type_icon.rb - module TypeIcon app/cells/cell/type_icon.rb - module Cell::TypeIcon Directory names should correspond to namespaces

apotonick commented 9 years ago

Exactly! :smile: It's a pure Rails autoloading issue! Thanks @Tab10id! @sdesbure - jump on the https://gitter.im/trailblazer/chat channel if you need more support. :wink:

sdesbure commented 9 years ago

Hello, thanks for the answer! I tried with app/cell but wasn't working either so I thought it was a different story! thanks guys

apotonick commented 9 years ago

No no, app/XXX/toplevel/bla.rb where the file bla.rb is Toplevel::Bla. The directory between app and toplevel could be dfjzkcxjalsdfjalskdfj1 and it would still work.