Using a dash for ruby ​​urls on rails

I have a folder like product_types. The controller file name is product_types_controller, and the class I have is ProductTypesController. I usually keep the _ format, which prefers rails, but I need to keep the syntax of the current page for search index reasons.

How do I get this controller to display in mysite.com/product-types and all pages in the product_types folder for mysite.com/product-types/some-page? Do I need to specify pages with - or should I use the _ syntax, and also just change the routes.

This is for the Rails 2.3.8 site.

thank

+3
source share
4 answers

RESTful, :

map.resources :product_types, :as => 'product-types'

, !

+2

Rails 3 -:

resources "product-types", :as => :product_types, :controller => :product_types
+6

If you use namespaces in your routes in Rails 3, you can use the following for dashes in URLs:

namespace :product_types, :path => "product-types" do
+4
source

In rails 3 you can:

resources :product_types, :path => '/product-types'
+1
source

Source: https://habr.com/ru/post/1778157/


All Articles