Ruby on rails 我如何在rails中获得twitter/friendfeed这样的主页URL?

Ruby on rails 我如何在rails中获得twitter/friendfeed这样的主页URL?,ruby-on-rails,friendly-url,Ruby On Rails,Friendly Url,我希望能够有像twitter一样友好的URL。如何在轨道上实现这一点 您可以使用gem。最简单的方法可能是在路由表的底部设置一条全面覆盖的路由。比如: map.connect '/:slug', :controller => 'users', :action => 'show' 然后在用户控制器中 def show @user = User.find_by_username(params[:slug]) end 我还建议捕获一个ActiveRecord::RecordNotF

我希望能够有像twitter一样友好的URL。如何在轨道上实现这一点

您可以使用gem。

最简单的方法可能是在路由表的底部设置一条全面覆盖的路由。比如:

map.connect '/:slug', :controller => 'users', :action => 'show'
然后在用户控制器中

def show
  @user = User.find_by_username(params[:slug])
end
我还建议捕获一个
ActiveRecord::RecordNotFound
以显示404页面。您可以在
ApplicationController
中放置类似的内容:

rescue_from ActiveRecord::RecordNotFound, :with => :not_found

然后定义一个方法
not\u found
来呈现错误页面或其他东西。

很酷。然而,我正在寻找一些不暴露控制器的东西。就像问题描述中给出的示例一样。