如何在Rails中将snake case转换为dash case

luc*_*cas 2 ruby-on-rails

我知道我可以转换"hello_world""hello-world"通过调用"hello_world".gsub('_', '-')。但只是好奇,是否有任何 Rails 助手,相当于下划线?有时不知道名字就很难找到这样的方法!

Eye*_*dic 5

dasherize 就在同一页上

"hello_world".dasherize # => 'hello-world'
Run Code Online (Sandbox Code Playgroud)