Hacker News new | past | comments | ask | show | jobs | submit login
Decorating ActiveRecord Accessor Methods (onehub.com)
13 points by charlesmount on June 25, 2009 | hide | past | favorite | 3 comments



Doing it this complex way would never have occurred to me. I would simply create an accessor method in the ActiveRecord model that doesn't exist in the database to take the hash and have it set the database field as a side effect, or in a before_save filter.


Yes, I suppose that would have worked as well, and would've been more in the spirit of the first attempt at a solution, but it wouldn't have been very general, and it certainly wouldn't have worked for all models in the application (without a lot of manual intervention).


Oh, it could be made general, just add the name of the actual datetime field as a parameter of the hash. Then you could drop the method into ActiveRecord. Anyway, the second solution is okay, because it is explicit enough. However it it still builds a dependency on define_attribute_methods.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: