如何重写url(除了在Ruby on Rails中使用名称空间的操作)?

时间:2022-08-29 16:49:23

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).

我正在运行Ruby on Rails 3,我想设置我的路由,以便使用名称空间重写url,除了一个操作(索引操作)。

In the routes.rb file I have:

的路线。rb文件给我:

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

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

因此,例如,“显示”/“创建新”帐户的url是:

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

我想重写/重定向这些url,除了'index'动作,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.

但它不工作。

1 个解决方案

#1


3  

try this

试试这个

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

#1


3  

try this

试试这个

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