ruby-on-rails - rails:为#<StateMachine::Machine:0xba3014ec> 调用了 protected 方法 `around_validation'

标签 ruby-on-rails ruby rails-activerecord

我正在尝试实现 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/

相关文章:

ruby-on-rails - HTML5 应用程序 list 未在 list 更改时清除缓存

ruby-on-rails - activesupport 回调中的堆栈级别太深

ruby-on-rails - 查找 10 天前创建的记录

ruby-on-rails - 在像 ruby​​-on-rails 这样的事件记录框架中工作时,使用外键约束是否有优势?

arrays - 匹配Array中的多个条件#reject

ruby-on-rails - 忽略事件记录 Rails 4 中为空的参数

ruby-on-rails - Rails 4 - Resque 后台作业中的印象派

ruby-on-rails - Array 或 ObjectType 作为参数 GraphQL rails

ruby-on-rails - 如果快速规范通过,如何让守卫只运行慢速规范

ruby-on-rails - Rack 中间件和线程安全