'some_contr...">

Rails 2.3.x equivalent of optional Rails3 route parameters

In Rails 3, I can do something like this:

match "/page(/:section)", :to => 'some_controller#page' 

And both /page and /page/some_section will appear on some_controller # page

Is there an equivalent to this in Rails 2.3.x ?? I can not find him

I am currently using two different routing methods:

 map.page '/page', :action => 'page' map.page_section '/page/:section', :action => 'page' 
+8
ruby-on-rails routing
source share
1 answer

The parameter becomes optional if you specify a default value.

 map.page '/page/:section', :action => 'page', :section => "default" 

If :section present, the value will be the current value. Otherwise, the default will be default and the router will not complain.

You can also set the value to nil .

 map.page '/page/:section', :action => 'page', :section => nil 
+14
source share

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


All Articles