我知道我可以通过调用 "hello_world".gsub('_', '-') 将
。但是是否有一个内置于 Rails 中的字符串方法,相当于 underscore ?有时候不知道名字很难找到这样的方法!"hello_world"
转换为 "hello-world"
最佳答案
dasherize
就在同一页上
"hello_world".dasherize # => 'hello-world'
关于ruby-on-rails - 如何在 Rails 中将 snake case 转换为 dash case,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63849959/