lucas
lucas

Reputation: 1151

How to convert snake case to dash case in Rails

I know I can convert "hello_world" to "hello-world" by calling "hello_world".gsub('_', '-'). But is there a string method for this built into Rails, something equivalent to underscore? Sometimes it's difficult to find such methods if you don't know the name!

Upvotes: 5

Views: 1737

Answers (1)

Eyeslandic
Eyeslandic

Reputation: 14890

dasherize right there on the same page

"hello_world".dasherize # => 'hello-world'

Upvotes: 9

Related Questions