Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm trying to implement the state_machine gem, in my rails project, I installed the gem, then I added the column "state" to my account_entries model:

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

Then in my account_entries model I added the state machine initial methon like this:

state_machine :state, :initial => :submitted do

end

Then in my view I show the time entry state:

account_entry.state

But when I try to create an account_entry from my application I get this error:

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

It says it's in the line 4 of my account_entries controller, this is the line 4 of my account_entries controller.

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

Is this a bug? Or is this my problem? How can I solve it? What does the error message mean?

like image 339
svelandiag Avatar asked Dec 20 '14 17:12

svelandiag


1 Answers

This is an open issue in state_machine. One fix which is listed there works around the issue by making the around_validation method public:

# 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
like image 114
fivedigit Avatar answered Sep 28 '22 01:09

fivedigit