OK, don’t laugh at me, I’m still learning. I have read the documentation on rails routing on the rails guide website. I’m working on a simple blog and want the routes to look like so:
mywebsite.com/category-name/article-name
The resources are article_categories and articles.
Right now, I can easily get this url structure with this route setup:
resources :article_categories, only: [:show], path: '' do
resources :articles, only: [:show], path: ''
end resources :article_categories, only: [:show], path: '' do
resources :articles, only: [:show], path: ''
end
However, it must live at the bottom of all routes. I completely understand why that is and how it works. But it seems this means you can only do one resource this way because any others you put below that will not work correctly (maybe I’m wrong about this…).
So my quest is for understanding on how I can create these routes so that they work even if they aren’t at the bottom of the routes file and at the same time, keep the same url helper names the other code provides.
I have tried some direct custom routes like “get “/:id”, as: :article_category …” and they worked but still had the same issue of needing to be at the bottom of the file.
I saw something about using constraints and what not but I’m not sure if that really applies. If what I’m looking for isn’t possible and the only option I have is to put the routes at the bottom for only one resource, Ok. But I thought this must be a gap in my understanding of rails routes.
Thank you.