zxyxta
Last Updated: February 25, 2016
·
433
· citizen428
B3881a28fe402dd2d1de44717486cae8

Automatic named scopes with state_machine

Personally I'm not really into state_machine's approach to scopes (e.g. Vehicle.with_state :parked), so I looked for a way to turn all defined states into proper named scopes (e.g. Vehicle.parked).

state_machines[:state].states.map do |state|
  scope state.name, -> { with_status state.name }
end
Say Thanks
Respond