C
C
CodeMaster_IM2014-04-16 22:41:56
Ruby on Rails
CodeMaster_IM, 2014-04-16 22:41:56

Routes.rb - How to remove controller name from URL?

There are two nested resources. How can I get rid of the nested resource controller name?
If you add :path => '' to the :bar resource, then the URI Pattern expects :foo_id instead of :id.
# routes.rb

namespace :admin do
  resources :foo, :path => '' do
    resources :bar
  end
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Fesenko, 2014-04-16
@CodeMaster_IM

Example::Application.routes.draw do
  scope :admin do 
    resources :foo, except: [:show], path: ''
    resources :foo, only: [], path: '' do 
      resources :bar, path: ''
    end
  end
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question