How can I make my rails app display url's as the user name?
In my Rails app a user can create one registry and the url's is for example:
How can I make that url be for example:
Thanks in advance.
The simplest way of doing this is by creating a new route at the bottom of your routes.rb file:
match "/:username" => "registries#show"
It's important to put this at the bottom of your routes.rb file as this will match any route of the format "/whatever" that doesn't match the routes preceding it.
This will point to the show action of your registries controller. So within that action you can just do
@user = User.find_by_username params[:username] @registry = @user.registry
The friendly_id gem and other slugging gems is, IMO, the easiest approach.
(And here's a friendly_id railscast.)
That said, it's easy to create a route that accepts legal slug values and redirect or look it up yourself.