Rails:路由问题

发布于 2024-11-26 17:05:05 字数 881 浏览 1 评论 0原文

我的路线中有这个:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城仅有旧梦在 2024-12-03 17:05:05

好吧:

resources :cvit

在这里查看文档: http://guides.rubyonrails.org/routing.html#singular -resources

或者更适合:

resources :cvits, :path => "cvit"

相同的文档页面。

Well:

resources :cvit

Check doc here: http://guides.rubyonrails.org/routing.html#singular-resources

Or a better fit:

resources :cvits, :path => "cvit"

Same doc page.

笑脸一如从前 2024-12-03 17:05:05

您只需要一个单一资源:

resouce :cvit

# instead of 
resources :cvits

请注意,您的控制器名称等仍将是复数(CvitsController)。为了以其他方式指定,您可以传递:

resource :cvit, :controller => 'cvit'

另外,请注意,当您执行此操作时,您没有索引操作。单一资源假设那里只有一件事,而不是很多。

假设这就是您所拥有的(单一资源),这比传递 path 选项更好。 path 选项只是覆盖名称而不是行为(即您仍然有一个索引,即使如果您处理的是单一资源,这没有意义)。

You just want a singular resource:

resouce :cvit

# instead of 
resources :cvits

Note that your controller names etc. will still be plural (CvitsController). In order to specify otherwise you can pass:

resource :cvit, :controller => 'cvit'

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. The path 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文