I created a simple application with a news module and defined the news as a separate mountable engine (it will be used on other projects too). I need to have the ability to mount the admin and user parts of the engine as separate routes on parent application. Now I can mount the whole engine as
Rails.application.routes.draw do
mount Jnews::Engine => "/news"
end
but I want to separate admin and user routes on parent app as /news for user and /admin/news for admins. Is this possible?
I think it depends on why you want to do this:
If you want to keep users and admins as separate code in the news gem – then you probably want to isolate 2 namespaces, and then mount each of those – which might involve having them as separate engines themselves.
If what you want is (and this is what I think you mean?) is to have the code shared in the news engine, but accessed at 2 different url’s in the main application based on whether the user is a plain user or an admin? What I would do in that case is something like this:
in the main application
in the engine routes
And then in the main application, based on what the user is (user or admin) you can redirect to either
app/newsorapp/admin/newsI hope that helps, I am not really sure about doing conditional routing.
However, here is a really good guide for routing: http://guides.rubyonrails.org/routing.html
You could perhaps try something along the lines of mounting an engine with dynamic routing?
where you end up with Jnew::Engine routed at either
user/newsandadmin/news? I have never actually done that, so I don’t know if it’s possible, however… maybe?Let me know if any of this helps 🙂
Cheers