Content

File: active record

I personally don’t think this is all that exciting — but I see this question asked a lot and just want something to point at from now on. Say you have several ‘nested’ has_many relations: class State < ActiveRecord::Base has_many :cities end class City < ActiveRecord::Base has_many :streets belongs_to :state end class Street < ActiveRecord::Base [...]

4 comments  ::  (Read the rest of this)

Every once in a while I see this little code snippet show up somewhere: script_console_running = ENV.include?(‘RAILS_ENV’) && IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?(‘console_with_helpers’) rails_running = ENV.include?(‘RAILS_ENV’) && !(IRB.conf[:LOAD_MODULES] && IRB.conf[:LOAD_MODULES].include?(‘console_with_helpers’)) irb_standalone_running = !script_console_running && !rails_running if script_console_running require ‘logger’ Object.const_set(:RAILS_DEFAULT_LOGGER, Logger.new(STDOUT)) end You see, if you drop this little gem in ~/.irbrc you’ll start getting the SQL [...]

 ::  (Read the rest of this)