1
我似乎很难从带有参数的URL获取用户名,但在查找ID时有效。使用参数从URL获取用户名
要想从这个网址的ID:www.foo.com/users/1/post/new
,你会使用:
User.find(params[:id]) # same as User.find(1)
我想我可以做同样的,based on the docs为:www.foo.com/users/joe/post/new
User.find_by(name: params[:name])
如何抢使用或find_by
方法使用参数的url的用户名?由于
谢谢。你是否还有其他方法被覆盖的网页链接? – Sylar
您不需要重写其他方法。就是这个。 –