在Rails中,如何从资源转到包含用连字符(如CSS类名称)样式化的类名的字符串?我想要一个方法#hyphenated_class_name或类似的东西,我可以应用于ActiveRecord资源,比如,类MyResource,然后回来my-resource.
eug*_*gen 10
你可能正在寻找underscore或者dasherize来自ActiveSupport :: Inflector的方法.您需要从类名到连字符串:
> PrettyPrint::SingleLine.name.demodulize.underscore.dasherize
=> "single-line"
Run Code Online (Sandbox Code Playgroud)