0

I'm trying to share routing concerns of my engine with the host application.

What I'd like to achieve is the following:

# MyGem/config/routes.rb
Rails.application.routes.draw do
  concern :commentable do
    resources :comments
  end
end

# HostApp/config/routes.rb
Rails.application.routes.draw do
  resources :posts, concerns: :commentable
end

Which results in No concern named commentable was found!.

I've tested just using the resource without the concern, and I can tell that the host is inheriting my routes, just not concerns.

This could be a load order issue, if the engine routes are loaded last. Which would explain why I could still see the resources comments.

The only thing I can think of is a building a method similar to devise_for :model.

Something along the lines of mygem_concerns, I suppose.

If anyone has any other suggestions I would truly appreciate the help.

fbelanger
  • 3,216
  • 1
  • 14
  • 27
  • Why does your engines routes file say MyGem.application.routes.draw instead of MyGem::Engine.routes.draw? – uday May 20 '16 at 05:52
  • Because you can do this as well to have full engine routes. If I put a resource or route in `mygem/config/routes.rb`, it will be accessible to the host application. – fbelanger May 20 '16 at 14:29
  • http://stackoverflow.com/questions/6118905/rails-3-1-engine-vs-mountable-app – fbelanger May 20 '16 at 17:36
  • Is this still the case in Rails 4.2? If so, that's unfortunate. I was under the impression that it had been fixed beyond the release of the concerns gem that I was using in 3.2. In 3.2 I ended up doing something like what you suggest RE devise. A method that declares the routes when called. Does the trick, but it'd be nice to be able to use the Rails Way. – Brendon Muir Sep 16 '16 at 01:52

0 Answers0