rails
Give your :reject_if some sugar
Tired of writing stuff like this?
accepts_nested_attributes_for :photo, :allow_destroy => true, :reject_if => proc { |attrs| reject = %w(title picture).all?{|a| attrs[a].blank?} }
Throw this snippet into init.rb into [...]
Teach models to stalk each other with Stalker
I often come by a case where models need to talk to each other. ModelA sometimes needs to ask ModelB to do something after_save. Usually you’d just use a callback.
class ModelA < ActiveRecord::Base after_save :update_model_b
def update_model_b ModelB.update! end end
This is obvious coupling. ModelA needs to know what to call in ModelB. This isn’t ModelA’s [...]
Integer_fu: store and manipulate many boolean values in a single integer column, with convenience
Link: http://github.com/maxim/integer_fu
I just finished the first version of a convenient plugin I’ve been writing for my own project. Integer_fu lets you map an integer attribute in your model to many possible boolean values, and then access them easily using hash-like syntax and some magical methods. Check it out down at Github. I tried to explain [...]