Redirecting /users/me to /me on Rails 3
I have just got my web app working with usernames being like this: http://myapp.com/dean
instead of http://myapp.com/users/dean
.
How do I go about redirecting th开发者_Python百科e /users/
to their username?
This is what my routes.rb file looks like (not the pages, etc):
resources :users
resources :sessions, :only => [:new, :create, :destroy]
match ':id' => 'users#show'
Removing the resources :users
breaks the site completely and shows No route matches
errors.
Try to add :path => '' to resources :users:
resources :users, :path => ''
match "/users/:name" => redirect("/%{name}")
well anyway I believe you're the one who decides which links to use so you might do sth like
match ':id' => 'users#show', :as => :sometwhere
and later in your views use
link_to somewhere_path( @user.name )
instead of
link_to user_path( @user )
精彩评论