Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Rails-路由到seo友好页面_Ruby_Ruby On Rails 3_Routing - Fatal编程技术网

Ruby Rails-路由到seo友好页面

Ruby Rails-路由到seo友好页面,ruby,ruby-on-rails-3,routing,Ruby,Ruby On Rails 3,Routing,我有一个为用户显示twitter帖子的网站。当前,当您在索引页上搜索其名称时,它会将您带到该url http://127.0.0.1:3000/user?utf8=%E2%9C%93&username=neiltyson&commit=Search 如何缩小此url,使其仅为 http://127.0.0.1:3000/user/neiltyson 编辑配置/路由以使用此选项: get "user/:username" => "user#search" 然后在app

我有一个为用户显示twitter帖子的网站。当前,当您在索引页上搜索其名称时,它会将您带到该url

http://127.0.0.1:3000/user?utf8=%E2%9C%93&username=neiltyson&commit=Search
如何缩小此url,使其仅为

http://127.0.0.1:3000/user/neiltyson
编辑配置/路由以使用此选项:

 get "user/:username" => "user#search"
然后在app/controller/users\u controller.rb中:

find_by只返回一个对象,首先会破坏它,不是吗?
 def search
    @user = User.find_by_username( params[:username] )
    respond_to do |format|
      format.html { redirect_to(@user) } # redirect to user#show action
    end
 end