Posts tagged ‘rails’

Riding Rails: jQuery: New Default

Riding Rails: jQuery: New Default.

This is timely.  I was getting a bit too used to adding jQuery to every project and removing prototype.  Needless to say, I’m excited at the prospect and hope to see Rails 3.1 soon!

Show ActiveRecord SQL in Rails 3 Console

If you want to show sql in your console for Active Record, then you may have run across the past Rails Recipes book or similar formulas for Rails < v3.0.  I just tweaked a formula I saw in that book to work with Rails 3 and here it is (This is designed to work on a Mac or most Linux flavors, Windows users, YMMV):

Create ~/.irbrc or add the following to your .irbrc, Mine is located at ~/.irbrc

if defined?(Rails) && Rails.env
  load File.dirname(__FILE__) + "/.railsrc"
end

Create ~/.railsrc or add the following to your ~/.railsrc:

def toggle_sql
  if ActiveRecord::Base.logger
    set_logger nil and return false
  else
    set_logger Logger.new(STDOUT) and return true
  end
end

def set_logger(logger)
  ActiveRecord::Base.logger = logger
  ActiveRecord::Base.clear_active_connections!
end
set_logger nil # start with the normal logger

Then, when you’re in your rails console world, just call toggle_sql. It returns true if the sql will be on, and false if the sql will be off.

Please feel free to leave suggestions and improvements here as I am always open to these suggestions.

Keep Multiple Ruby Projects Separated

RVM LogoHow do I keep multiple Ruby projects separate?.

This is really helpful article for those of us that have many projects that span great amounts of time.  It gives you the high level of how to leverage RVM, with Bundler for managing deployment recipes on servers that may have different versions of everything for each project.

I am going to probably build on this with an example, since I need to use this technique on my production server.  Stay tuned, as he states in the article, I always have much more going on than I can actually accomplish, so hope to do this on the next weekend.

© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top