Forum: Ruby on Rails Rewrite hyphen to underscore

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
dan.kubb (Guest)
on 2005-11-15 12:01
(Received via mailing list)
I have a Routes question.  Say I have the following routes.rb
configuration:

ActionController::Routing::Routes.draw do |map|
   map.connect ':controller/:action', :action =>
'index', :requirements => { :action => /(?:[a-z](?:-?[a-z]+)*)/ }
   map.connect ':controller/:id',     :action =>
'show',  :requirements => { :id     => /\d+/                    }
   map.connect ':controller/:id/:action'
end

Notice that I want to use hyphens in the action name?  Is there
any way to "rewrite" this inside Rails so that the hyphen becomes
an underscore?

So for example I want:

   /person/list-all

to map to:

   :controller => 'person', :action => 'list_all'

I prefer to use a hyphens in my URIs because in an underlined link
the underscore character can sometimes be mistaken for a space.

Also, for the third connect call, do I have to specify the requirements
for the :action and :id that were specified earlier if I want the same
requirements to continue to apply?

--

Thanks,

Dan
francois.beausoleil (Guest)
on 2005-11-15 15:49
(Received via mailing list)
Hello Dan !

2005/11/15, Dan K. <removed_email_address@domain.invalid>:
> Notice that I want to use hyphens in the action name?  Is there
> any way to "rewrite" this inside Rails so that the hyphen becomes
> an underscore?

I blogged about that about a month ago:
http://blog.teksol.info/articles/2005/10/25/action...

Hope that helps !
This topic is locked and can not be replied to.