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
Written by Michael Kohl
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#