geekq / workflow

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

default_scope breaks initial state #121

Closed paulslaby closed 2 years ago

paulslaby commented 10 years ago

Not sure, if it is problem of this gem, but people might be trying to find solution here.

This is my code:

class Recipe < ActiveRecord::Base default_scope {where(:state => :approved)}

include Workflow workflow_column :state workflow do state :new do event :approve, transitions_to: :approved end state :approved end end

when I run rails c: Recipe.new.state => :approved

when commenting out defaul_scope, it is ok.

paulslaby commented 10 years ago

I use this workaround:

def initialize(attrs={}, *args) super({:state => :new}.merge!(attrs), args) end