Skip to content

Instantly share code, notes, and snippets.

@will3216
will3216 / gist:a44c9ad3a18d69abaf67
Created July 1, 2015 20:22
Log information about callbacks for the Lifecycle of a Rails 3.2.19 (Wraps state-machine callbacks as well if state-machine is being used)
# This is used for debugging callbacks chains, to use this code:
# 1. Drop this into an initializer in your rails app
# 2. Set the LG_FILE_PATH to the file location you want the logging to go too
# 3. Set MODEL_TO_DEBUG to the class you want to debug, ie: MODEL_TO_DEBUG
# 4. Change the print_string method to save the relevant information. It has
# access to any instance methods on the object presently in the callback chain
# Note: Not sure how compatible this is with other versions of rails/state-machine
# VERSIONS PATCHED
# State-Machine 1.1.2
@sdball
sdball / sandi_metz_rules_for_developers.md
Created January 18, 2013 18:47
Rules for good development from Sandi Metz

Sandi Metz’ rules for developers

  1. Your class can be no longer than a hundred lines of code.
  2. Your methods can be no longer than five lines of code
  3. You can pass no more than four parameters and you can't just make it one big hash.
  4. In your controller, you can only instantiate one object, to do whatever it is that needs to be done.
  5. Your view can only know about one instance variable.
  6. Your Rails view should only send messages to that object i.e., no Demeter violations.[ "thunder dome principal". Translated: one model in, one model out! ]
  7. Rules are meant to be broken if by breaking them you produce better code. [ ...where "better code" is validated by explaining why you want to break the rule to someone else. ]