我在嘗試更改URL名稱。是否有一種使用名稱空間更改URL的方法?
這是我的routes.rb:
namespace :user_management do
resources :user do
collection do
get 'main'
end
end
end
match ':controller(/:action(/:id(.:format)))', :via => [:get, :post]
耙路線:
Prefix Verb URI Pattern Controller#Action
root GET / user_management/login#login
user_main_user_management_user_index GET /user_management/user/main(.:format) user_management/user#main
user_management_user_index GET /user_management/user(.:format) user_management/user#index
POST /user_management/user(.:format) user_management/user#create
new_user_management_user GET /user_management/user/new(.:format) user_management/user#new
edit_user_management_user GET /user_management/user/:id/edit(.:format) user_management/user#edit
user_management_user GET /user_management/user/:id(.:format) user_management/user#show
PATCH /user_management/user/:id(.:format) user_management/user#update
PUT /user_management/user/:id(.:format) user_management/user#update
DELETE /user_management/user/:id(.:format) user_management/user#destroy
GET|POST /:controller(/:action(/:id(.:format))) :controller#:action
我的網址是:
localhost/user_management/user/main
而且我想:
localhost/user_main
我試過,但它不工作:
namespace :user_management do
resources :user do
collection do
get 'main', as: :user_main
end
end
end
我試過,但沒有工作之一:
namespace :user_management do
resources :user do
collection do
get '/user_main', as: "user_management/user#main
end
end
end
您的上一個代碼在語法上無效。 – sawa
是的,我知道我不知道該怎麼嘗試。 –
首先你要弄明白爲什麼它在語法上不正確。我建議看看IRB在解釋它時如何顯示其線條標記。 '3''是重要的,閱讀IRB文檔將解釋發生了什麼。 –