I’ve included state_machine in my class and got exited while manipulating with it in the console. However, my excitement gone when I tried to use it in an application. I got
wrong number of arguments (2 for 0)
error in “initialize” method of my state_machined class “request” when I call user.requests.build.
“initialize” method looks like
def initialize
super()
end
because the gem’s creator told me so at https://github.com/pluginaweek/state_machine. Class definition starts with
class Request < ActiveRecord::Base
attr_accessible :subject, :details, :assigned_to, :log, :status, :solution
belongs_to :user
belongs_to :assignee, class_name: "User", foreign_key: "assigned_to"
I think that the error caused by associations that the initializer are not aware of. Am I right? What can I do?
The example given in the README was not for ActiveRecord integrations — just for plain Ruby classes. In an ActiveRecord integration there’s no need to do anything special in your initialize method in order for state_machine to work. By overriding your initialize method, you’re changing the method signature that ActiveRecord depends on. If you’re not doing anything else in that override, I suggest you remove it altogether.
Hope this helps!