开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜