我刚刚让我的web应用程序与用户名类似:http://myapp.com/dean而不是http://myapp.com/users/dean。
如何将/users/重定向到他们的用户名?
这是我的routes.rb文件的样子(不是页面,等等):
resources :users
resources :sessions, :only => [:new, :create, :destroy]
match ':id' => 'users#show' 删除resources :users会完全中断站点并显示No route matches错误。
发布于 2011-07-05 22:44:24
尝试将:path => '‘添加到资源:users:
resources :users, :path => ''发布于 2011-07-05 17:06:45
match "/users/:name" => redirect("/%{name}")
好吧,不管怎样,我相信你是决定使用哪个链接的人,所以你可能会这样做
match ':id' => 'users#show', :as => :sometwhere稍后在您的视图中使用
link_to somewhere_path( @user.name )而不是
link_to user_path( @user )https://stackoverflow.com/questions/6576862
复制相似问题