Reputation: 573
My Url is http://www.example.com/players/playersdetail/100006 i have a players controller. I need to remove or hide controller and method name (players/playersdetail) from url and i want name in place of id(100006)
How to achieve in Ruby On Rails?
Routes is
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
Upvotes: 0
Views: 952
Reputation: 3868
Your routes.rb something like this:
resources :players
which produces routes of the form /entries/24225252/foo
.
There exists a :path argument that allows you to use something besides the default name entries. For example:
resources :players, :path => 'my-cool-path'
will produce routes of the form /my-cool-path/2012/05/10/foo.
But, if we pass an empty string to :path, we see the behaviour you're looking for:
resources :players, :path => ''
will produce routes of the form /2012/05/10/foo.
Also another option:
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'
Upvotes: 1