我的网址是http://www.example.com/players/playersdetail/100006我 有一个球员控制器。我需要删除或隐藏控制器和 来自网址的方法名称(players / playersdetail),我希望名称到位 id(100006)
如何在Ruby On Rails中实现?
路线
Something::Application.routes.draw do
get "players/search"
post "players/search"
get "players/playerslist"
get "players/playersdetail"
get "players/list"
get "players/followers"
get "players/following"
end
答案 0 :(得分:1)
Your::Application.routes.draw do
scope ":name" do
get '', to: 'players#show'
get :about, to 'players#about'
get :friends, to 'players#friends
end
end
答案 1 :(得分:1)
你的routes.rb是这样的:
resources :players
生成form /entries/24225252/foo
的路由。
存在一个:path参数,允许您使用除默认名称条目之外的内容。例如:
resources :players, :path => 'my-cool-path'
将生成/my-cool-path/2012/05/10/foo.
但是,如果我们将空字符串传递给:path,我们会看到您正在寻找的行为:
resources :players, :path => ''
将生成/2012/05/10/foo.
另一种选择:
get ':year/:month/:day/:title' => 'some_controller#show', :as => 'players'
put ':year/:month/:day/:title/edit' => 'some_controller#edit', :as => 'edit_players'
delete ':year/:month/:day/:title' => 'some_controller#destroy', :as => 'destroy_players'