新手问题 URL 中的问题

gechentuo · August 12, 2013 · Last by gechentuo replied at August 16, 2013 · 2095 hits

环境 ruby2.0.0+rails4.0

http://localhost:3000/users/3/edit

http://localhost:3000/users/3edit;

这两个地址有什么不同?求助..

第一个匹配的 route 是 /users/:id/edit,所以 params[:id] 赋值为 3 第二个匹配的 route 是 /users/:id,所以 params[:id] 的赋值为 3;edit 可参考:http://guides.rubyonrails.org/routing.html

正确答案见二楼。

第二个是 rails 1 的写法,分号后的部分叫做 url matrix parameter, 但没流行起来,没进到标准里,rails 就改回正常的 url 写法了

You need to Sign in before reply, if you don't have an account, please Sign up first.