How to rewrite URLs other than using namespaces in Ruby on Rails?

I am running Ruby on Rails 3, and I would like to configure my routes to rewrite URLs using namespaces except for the action (index action).

In the routes.rb file, I have:

namespace "users", :path => "user" do
  resources :accounts
end

So, for example, the URLs for "show" / "create new" accounts are:

http://<site_name>/user/accounts/1
http://<site_name>/user/accounts/new

I would like to rewrite / redirect these urls except for the "index" action like / to

# For the 'index' action I would like to use plural 'users' instead of 'user'
http://<site_name>/users/accounts
# and
http://<site_name>/users

How to do it?


I tried this one

namespace "users", :path => "user", :except => :index do
  resources :accounts
end

but that will not work.

+3
source share
1 answer

try it

namespace "users",: path => "user" do
  resources: accounts,: except =>: index
end
+3

Source: https://habr.com/ru/post/1791826/


All Articles