ltdev
ltdev

Reputation: 4467

Renaming specific path on resource route

I have set this resource route in my Routes.rb

  namespace :admin do
    resources :posts
  end

How can I rename the route name and path name specifically for index, which at the moment is

# route
 admin_posts GET    /admin/posts(.:format)            admin/posts#index

# path
admin_posts_path

rename to

dashboard_path

Upvotes: 0

Views: 1091

Answers (2)

Sebastián Palma
Sebastián Palma

Reputation: 33420

After your namespace definition in the routes.rb file, you can create a new "entry" for such controller and action, like:

namespace :admin do
  resources :posts
end
get 'dashboard', to: 'admin/posts#index', as: :dashboard

Upvotes: 2

Denis Romanovsky
Denis Romanovsky

Reputation: 298

Try this:

resources :posts, except: [:index]
get 'your_url', to: 'controller@action', as: 'dashboard_path'

There is no support for renaming inside resources.

Upvotes: 1

Related Questions