Rails:路由问题
我的路线中有这个:
resources :cvits
它产生这些路线:
cvits GET /cvits(.:format) {:controller=>"cvits", :action=>"index"}
POST /cvits(.:format) {:controller=>"cvits", :action=>"create"}
new_cvit GET /cvits/new(.:format) {:controller=>"cvits", :action=>"new"}
edit_cvit GET /cvits/:id/edit(.:format) {:controller=>"cvits", :action=>"edit"}
cvit GET /cvits/:id(.:format) {:controller=>"cvits", :action=>"show"}
PUT /cvits/:id(.:format) {:controller=>"cvits", :action=>"update"}
DELETE /cvits/:id(.:format) {:controller=>"cvits", :action=>"destroy"}
但我希望我的网址是单一的(例如/cvit/,/cvit/new,/cvit/:id)。改变这个最简单的方法是什么????
谢谢!!!!
已解决:弄清楚了,我做了:
资源:cvits,:path => 'cvit'
I have this in my routes:
resources :cvits
which produces these routes:
cvits GET /cvits(.:format) {:controller=>"cvits", :action=>"index"}
POST /cvits(.:format) {:controller=>"cvits", :action=>"create"}
new_cvit GET /cvits/new(.:format) {:controller=>"cvits", :action=>"new"}
edit_cvit GET /cvits/:id/edit(.:format) {:controller=>"cvits", :action=>"edit"}
cvit GET /cvits/:id(.:format) {:controller=>"cvits", :action=>"show"}
PUT /cvits/:id(.:format) {:controller=>"cvits", :action=>"update"}
DELETE /cvits/:id(.:format) {:controller=>"cvits", :action=>"destroy"}
but I would like my urls to be singular (eg /cvit/, /cvit/new, /cvit/:id). What would be the easiest way to change this??????
Thanks!!!!
SOLVED: Figured it out, I did:
resources :cvits, :path => 'cvit'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧:
在这里查看文档: http://guides.rubyonrails.org/routing.html#singular -resources
或者更适合:
相同的文档页面。
Well:
Check doc here: http://guides.rubyonrails.org/routing.html#singular-resources
Or a better fit:
Same doc page.
您只需要一个单一资源:
请注意,您的控制器名称等仍将是复数(CvitsController)。为了以其他方式指定,您可以传递:
另外,请注意,当您执行此操作时,您没有索引操作。单一资源假设那里只有一件事,而不是很多。
假设这就是您所拥有的(单一资源),这比传递
path
选项更好。path
选项只是覆盖名称而不是行为(即您仍然有一个索引,即使如果您处理的是单一资源,这没有意义)。You just want a singular resource:
Note that your controller names etc. will still be plural (CvitsController). In order to specify otherwise you can pass:
Also, note that when you do this you have no index action. Singular resources assume there's only one thing there, instead of being many.
Assuming that is what you have (a singular resource), this is better than passing the
path
option. Thepath
option is just overriding the name and not the behavior (i.e. you still have an index, even though that doesn't make sense if you're dealing with a singular resource).