我使用gem state_machine - Official
每个州都有“人名”。通过我尝试过的文档和API:
my_model.rb中的
state_machine :initial => :new do
state :new, :human_name => 'Added and not accepted'
...
my_view.haml 中的
%p= MyModel.human_state_name(@item.state_name)
%p= @item.human_state_name
这两种变体只返回'new'而不是'Added and not accepted'。我该做什么?我在设置human_name或获取human_name时犯了错误?
更新 适用于:
en:
activerecord:
state_machines:
mymodel: # model name
states:
new: 'Added and not accepted' # state name
答案 0 :(得分:9)
您无需将:human_name选项传递给状态机。只需为您的语言定义翻译:
en:
activerecord:
state_machines:
mymodel: # model name
state: # state name
states:
new: 'Added and not accepted'
events: # you can also define translations for the events
some_event: 'put custom translation here'