开发者

How can I get a hyphenated class name from a resource in Rails?

开发者 https://www.devze.com 2023-04-02 14:15 出处:网络
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

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消