SQL Logging in ruby console
20 Dec 2009
Tags:
log, console, sql
We can do that by typing the following in the console (remember to reload!)
>> ActiveRecord::Base.logger = Logger.new(STDOUT)
But what if we want to turn this off? Just set the logger to nil. (then reload!) Here are two methods that will help automate this feature. Place them in your .irbrc file
require 'logger' def logger_on set_logger_to Logger.new(STDOUT) end def logger_off set_logger_to nil end def set_logger_to(logger) ActiveRecord::Base.logger = logger reload! end
Then you can just type logger_on to turn on SQL logging, or logger_off to turn it off.
Colors in Ruby Console Using Wirble
20 Dec 2009
Tags:
log, console, gem, wirble
If you want to have colors in your console, install the wirble gem (Read the documentation).
For some reason, I can't override the colors when I follow the instructions in the README. In case someone's also experiencing this, you can try merging the colors in the Wirble::Colorize::DEFAULT_COLORS constant. Then call the init and colorize methods.
Here's mine (same as with vim's syntax highlighting for ruby and haml).
Wirble::Colorize::DEFAULT_COLORS.merge!({ # delimiter colors :comma => :none, :refers => :none, # container colors (hash and array) :open_hash => :purple, :close_hash => :purple, :open_array => :purple, :close_array => :purple, # object colors :open_object => :light_red, :object_class => :white, :object_addr_prefix => :blue, :object_line_prefix => :blue, :close_object => :light_red, # symbol colors :symbol => :red, :symbol_prefix => :red, # string colors :open_string => :purple, :string => :red, :close_string => :purple, # misc colors :number => :red, :keyword => :brown, :class => :green, :range => :none })
Expire Session after 30 minutes
01 Dec 2009
Tags:
session
Add the following code in your application_controller
before_filter :check_session_lifetime before_filter :update_session_timestamp def check_session_lifetime if session[:updated_at] && 30.minutes.since(session[:updated_at]) < Time.now reset_session # add application specific functions you like done here. end end def update_session_timestamp session[:updated_at] = Time.now end