pluginaweek / state_machine

Adds support for creating state machines for attributes on any Ruby class
http://www.pluginaweek.org
MIT License
3.74k stars 505 forks source link

hack for state_machine/rails-4.2 compatibility #326

Closed huoxito closed 9 years ago

huoxito commented 9 years ago

state_machine overrides column_defaults but as of rails 4.2 it needs to override default_attributes to get the same behaviour.

Ideally we need to figure a less hacky / dangerous way to set default initial states for the machine.

current rails edge / rails 4.1.6:

https://github.com/rails/rails/blob/c4767e13d4ae927e6d605cad3846c9807745b883/activerecord/lib/active_record/core.rb#L264 https://github.com/rails/rails/blob/v4.1.6/activerecord/lib/active_record/core.rb#L186

ps. putting this out there just in case someone else notice the issue and need a fix or perhaps even figure a much better solution (given this project is no longer maintained)

exAspArk commented 9 years ago

@huoxito thanks for your solution. Currently in Rails 4.2 default_attributes renamed to _default_attributes.

I also made some very dirty things to make it work with Rails 4.2: https://gist.github.com/exAspArk/88294f3e53af202428ed

huoxito commented 9 years ago

hey @exAspArk thanks for the heads up, pls checkout https://github.com/pluginaweek/state_machine/pull/333, that should work on latest activerecord 4.2 (at least it's working for spree). would you let me know if that works for you too?

exAspArk commented 9 years ago

@huoxito your solution from #333 looks much better and it works for me too, thanks!

For now, I'm just trying to migrate my old rails project to 4.2 and not sure about continuing using state_machine gem or at least using it with mongoid or datamapper. It already has tons of forks and the existing code base seems to me a bit complex. On the other hand, there are a lot of more elegant "state machines" for me, e.g. statesman.

If you want to continue maintaining it as a new project I think it is a good idea and I hope somebody will come and help you, good luck! :+1: :smile_cat: :santa:

abepetrillo commented 4 years ago

Just hit this myself. Is #333 released in an actual release? Latest seems to be 1.2.0 which was released much earlier than #333