gpt4 book ai didi

ruby-on-rails - rails:为# 调用了 protected 方法 `around_validation'

转载 作者:数据小太阳 更新时间:2023-10-29 07:09:47 24 4
gpt4 key购买 nike

我正在尝试实现 state_machine gem,在我的 rails 项目中,我安装了 gem,然后我将“state”列添加到我的 account_entries 模型中:

  def change
add_column :account_entries, :state, :string
end

然后在我的 account_entries 模型中,我添加了状态机初始方法,如下所示:

state_machine :state, :initial => :submitted do

end

然后在我看来我显示时间进入状态:

account_entry.state

但是当我尝试从我的应用程序创建一个 account_entry 时,我得到了这个错误:

protected method `around_validation' called for #<StateMachine::Machine:0xba3014ec>

它说它在我的 account_entries Controller 的第 4 行,这是我的 account_entries Controller 的第 4 行。

e.account_entries.create(params.require(:account_entry).permit(:time, :account_id))

这是一个错误吗?或者这是我的问题?我该如何解决?错误信息是什么意思?

最佳答案

这是 an open issue in state_machine .那里列出的一个修复程序通过公开 around_validation 方法解决了这个问题:

# config/initializers/state_machine_patch.rb
# See https://github.com/pluginaweek/state_machine/issues/251
module StateMachine
module Integrations
module ActiveModel
public :around_validation
end
end
end

关于ruby-on-rails - rails:为#<StateMachine::Machine:0xba3014ec> 调用了 protected 方法 `around_validation',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27582563/

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