Rails 4 - How to map routes in a namespace

Hi, I have an admin panel controller and there are many controllers in the admin panel. I want to map routes, usually without the namespace that I used

match ':controller(/:action(/:id))', :via => [:get, :post]

I want this in the namespace controller of the current current

router.rb

namespace :admin do

get '', to: 'dashboard#index', as: '/'

get 'dashboard/index'

##AUTHENTICATION
get 'login/index'
get 'login/logout'
post 'login/attempt_login'
get 'login/attempt_login'

##PAGES
get 'pages/index'
get 'pages/add_new'
get 'pages/edit'
post 'pages/create'
post 'pages/update'
post 'pages/task'
get 'pages/task'

##USERS
get 'users/index'
get 'users/edit'
get 'users/delete'
get 'users/destroy'
get 'users/update'
get 'users/add_new'
post 'users/create'
post 'users/update'
post 'users/task'

#USER GROUPS
get 'user_group/index'
get 'user_group/add_new'
get 'user_group/edit'
post 'user_group/create'
post 'user_group/update'
post 'user_group/task'

#USER GROUPS
get 'access_sections/index'
get 'access_sections/add_new'
post 'access_sections/create'
post 'access_sections/update'
post 'access_sections/task'

end

Any solution please?

+4
source share
2 answers

You simply carry the routes that you declare in the namespace, for example:

namespace :login do
   get 'index'
   get 'logout'
end

http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

+6
source

For example, we have orders that can be canceled:

Following description in routes.rb

  resources :orders do
      post :cancel, to: 'orders/cancellations#cancel'
  end

app/controllers/orders/cancellations_contoller.rb

module Orders
  class CancellationsController
    def cancel
      @order = Order.find(params[:id]).cancel
    end
  end
end

.

,

+2

All Articles