Reputation: 6451
I'm creating a Blog
mountable engine that people will use as their complete application.
If someone current adds my gem into their Rails app, it will work under the /blog
url of their site (since the engine is namespaced).
How can allow them to just use the gem as their whole application?
i.e. They include gem "Blog"
in their gem file and their http://example.com/
shows the application the gem provides.
Any help would be greatly appreciated.
Upvotes: 2
Views: 691
Reputation: 6451
Turned out to be the most simplest thing. All that was needed was this in the routes:
mount Blog::Engine => "/"
Upvotes: 1
Reputation: 3815
This may be a good case for a routing concern (newly introduced in Rails 4). What these do is allow you to bundle & reuse a set of routes. So, with a very simple blogging application, you might have something like this:
concern :bloggable do
resources :articles do
resources :comments
end
end
All the routing that's specific to your gem can go inside the bloggable concern. The default way to inject this into an app would then look a bit like this:
scope :blog do
concerns :bloggable
end
This will give the behavior you already have - all the routing associated with the blog under the blog/
directory. However, this would easily let the user change it. To put it on the root scope as you suggested, the user would have to add concerns :bloggable
to the base scope of their routing file, and it will work as intended.
Upvotes: 2