B
B
bismoney2015-11-08 00:35:29
Ruby on Rails
bismoney, 2015-11-08 00:35:29

Date in url how to implement?

Hello.
There is a routing of this format

resources :post_categories, :path => '', :only => [:show] do
    resources :posts, :path => '', :only => [:show]
  end

I get what I need
/category/id
/category

How correctly to enter dates in this routing?
/category/2015/11/08/id
Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Demidenko, 2015-11-08
@bismoney

As I wrote, you should learn the basics.
In this case it is
For example:
Params[:year], params[: month], params[: day], params[: id] will be available in the controller
Again, study the rails guide)
Your comment will probably be like this:

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question