A
A
Anton2016-02-03 17:38:28
Ruby on Rails
Anton, 2016-02-03 17:38:28

How to make a redirect in routes for multilevel resources?

There are, for example, the following resources:

resources :publishers do
  resources :magazines do
    resources :photos
  end
end

How to redirect the /publishers/1/magazines/2 page to
/ publishers/1/magazines/2/photos ? Added this to :magazines:

/publishers/:publisher_id/magazines/:magazine_id, to: redirect('что_то')

But the redirect didn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy Trebin, 2016-02-03
@evgeniy_trebin

Try this

resources :publishers do
  resources :magazines, except: :show do
    get :show, to: redirect { |path_params, req| "/publishers/#{path_params[:publisher_id]}/magazines/#{path_params[:magazine_id]}/photos" }
    resources :photos
  end
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question