Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rewrite URLs except for an action using namespaces in Ruby on Rails?

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

In the routes.rb file I have:

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

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

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

I would like to rewrite/redirect those URLs, except for the 'index' action, as/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 that?


I tryed this

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

but it doesn't work.

like image 695
user502052 Avatar asked Dec 09 '25 12:12

user502052


1 Answers

try this

namespace "users", :path => "user" do
  resources :accounts, :except => :index
end
like image 192
Rishav Rastogi Avatar answered Dec 11 '25 01:12

Rishav Rastogi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!