[英]Using Dashes for urls in ruby on rails
I have a view folder product_types. 我有一个视图文件夹product_types。 The name of the controller file is product_types_controller and the class I have is ProductTypesController.
控制器文件的名称是product_types_controller,我的类是ProductTypesController。 I'd normally keep the _ format that rails prefers but I need to keep the current page syntax for search index reasons.
我通常会保留rails喜欢的_格式,但我需要保留当前页面语法以用于搜索索引。
How do I get this controller to show up for mysite.com/product-types and all pages in the folder product_types to appear for mysite.com/product-types/some-page? 如何让这个控制器显示mysite.com/product-types和文件夹product_types中的所有页面以显示mysite.com/product-types/some-page? Do I need to name the pages with - or should I use the _ syntax as well and just change the routes.
我是否需要使用 - 或者我应该使用_语法来命名页面,只需更改路由。
This is for a Rails 2.3.8 site. 这是一个Rails 2.3.8站点。
Thanks 谢谢
对于Rails 3,您必须以不同方式执行此操作:
resources "product-types", :as => :product_types, :controller => :product_types
如果您在Rails 3中的路由中使用名称空间,则可以在URL中使用以下短划线:
namespace :product_types, :path => "product-types" do
If you're using RESTful routes, you can do this: 如果您正在使用RESTful路由,则可以执行以下操作:
map.resources :product_types, :as => 'product-types'
I hope this helps! 我希望这有帮助!
在rails 3中,您可以:
resources :product_types, :path => '/product-types'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.