geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

support for enum #191

Closed openxyz closed 2 years ago

openxyz commented 7 years ago

I store workflow_state as integer in db using enumerize gem ,like {draft:1, submtted:2,passed:3} but can`t work with error message :

> o.current_state 
undefined method 'to_sym' for 8:Fixnum

it seems the current_state method use value of before_typecast

so i override the load_workflow_state in my model:

def load_workflow_state
   send(self.class.workflow_column).to_sym
end 

def persiste_workflow_state value
    update_columns self.class.workflow_column => self.send(self.class.workflow_column workflow_state).find_value(value)
end

it seems work!