gpt4 book ai didi

ruby - state_machine ruby​​ gem 中状态的 human_name

转载 作者:数据小太阳 更新时间:2023-10-29 06:58:54 26 4
gpt4 key购买 nike

我使用 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"而不是“已添加但未接受”。我该做什么?我在设置 human_name 或获取 human_name 时出错了吗?

更新工作于:

en:
activerecord:
state_machines:
mymodel: # model name
states:
new: 'Added and not accepted' # state name

最佳答案

您不需要将 :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'

关于ruby - state_machine ruby​​ gem 中状态的 human_name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10752464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com