In Rails, how do I go from a resource to a string containing its class name stylized with hyphens开发者_开发知识库 (as in a CSS class name)? I'd like a method #hyphenated_class_name
or the like that I can apply to ActiveRecord resource of, say, class MyResource
, and get back my-resource
.
You're probably looking for underscore
or dasherize
methods, from ActiveSupport::Inflector. You need both to go from a class name to hyphenated string:
> PrettyPrint::SingleLine.name.demodulize.underscore.dasherize
=> "single-line"
精彩评论