有没有办法为某些符号设置自定义的人性化结果?

时间:2013-11-28 19:04:00

标签: ruby-on-rails

当向用户显示符号值时,我知道您可以通过执行类似

的操作使其更具人性化
my_symbol.to_s.humanize

有没有办法为某些符号自定义该调用的结果?对于大多数情况,它工作正常,但有时候它不是你想要的。例如,如果我的状态字段包含已排队,已发送,已重新发送等选项,则可以使用符号:queued:sent,但重新发送的内容是什么? :resent:re_sent对于编码来说已经足够好了,但人性化的形式还不足以进行显示。

1 个答案:

答案 0 :(得分:1)

详情here

$ rails console
Loading development environment (Rails 4.0.1)
irb(main):001:0> :re_sent.to_s.humanize 
=> "Re sent"
irb(main):002:0> ActiveSupport::Inflector.inflections(:en).human(/re_sent/, "Re-sent") 
=> [[/re_sent/, "Re-sent"]]
irb(main):003:0> :re_sent.to_s.humanize
=> "Re-sent"