开发者

Redirecting /users/me to /me on Rails 3

开发者 https://www.devze.com 2023-03-17 18:56 出处:网络
I have just got my web app working with usernames being like this:http://myapp.com/dean instead of http://myapp.com/users/dean.

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 )
0

精彩评论

暂无评论...
验证码 换一张
取 消