Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics AR Extensions Stateful Models

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

Hello please help I followed all the steps that Catlin explained, but when I try to create a time entry in the employee page I get the error

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

it says the problem is the file time_entries_controller.rb line 4

this is the line

e.time_entries.create(params.require(:time_entry).permit(:time, :account_id))

Any idea what did I do wrong?

2 Answers

Finally I could fix it, that's a bug of the state model https://github.com/pluginaweek/state_machine/issues/251

One solution is to make the around_validation method public, here is the procedure:

Create a file patch state_machine_patch.rb in config/initializers

and paste this code in that file:

module StateMachine
  module Integrations
     module ActiveModel
        public :around_validation
     end
  end
end

after this your problems are gonna be fixed, but if you still get problems read this comment on the issue https://github.com/pluginaweek/state_machine/issues/251#issuecomment-32133267

Hope it helps someone else

Michael Hall
PLUS
Michael Hall
Courses Plus Student 30,909 Points

I had this same error and solved it by adding

gem 'state_machines-activerecord'

to the gemfile