Answer the question
In order to leave comments, you need to log in
Date in URL repeat, didn't figure it out?
So I could not figure it out .... I ask for help friends.
Now there is routes.rb
resources :post_categories, path: '', only: :show do
resources :posts, path: '', only: :show
end
def show
@posts = PostCategory.find_by!(seo_url: params[:post_category_id]).posts.find(params[:id])
end
resources :post_categories, path: '', only: :show do
resources :posts, path: '/:year/:month/:day', only: :show, constraints: { year: /\d{4}/, month: /\d{2}/, day: /\d{2}/ }
end
params[:year], params[:month], params[:day]
Answer the question
In order to leave comments, you need to log in
You have some kind of oil. In order to get a Post, it is enough to pass its id. Why do you need another category and date in the url, I don’t understand. Typically, if a url like site.com/category_name/year/month/day is used, it will return a group of objects filtered by category and date. If you need such behavior, add the index method to the PostsController and set up such a route to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question