Answer the question
In order to leave comments, you need to log in
How to correctly resolve routing for different URLs?
Actually, I made it so that the project can be with a category. But at the same time, the project can be without a category. And immediately ran into a problem.
I can display and process either projects nested in a category or projects without a category.
routes.rb
get '../:project_url', to: 'project#index'
либо
get '../:category_url', to: 'project#category'
либо
get '../:category_url/:project_url', to: 'project#category'
Answer the question
In order to leave comments, you need to log in
make paths for a project without a category and for a project with a category, and when rendering, write a helper that checks the object for the presence of a category and sets the desired path.
the first thing that came to mind
Try
get '../:category_url/:project_url', to: 'project#category'
Raise higher in the code than other options, then this will have a higher priority. raise ActionController::RoutingError.new('Not Found')
and so on down the list.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question