Thursday, November 29, 2012

Sphinx fails to start with rake ts:start or rake ts:rebuild

$ rake ts:start
Failed to start searchd daemon. Check ../log/searchd.log.
Failed to start searchd daemon. Check ../log/searchd.log
Be sure to run thinking_sphinx:index before thinking_sphinx:start
Almost always is the case for me that searchd is already running / orphaned and needs to be killed. Run
$ps -ax | grep searchd
shows that its already running
49630 ttys000    0:00.06 searchd --pidfile --config ../config/development.sphinx.conf
49644 ttys001    0:00.00 perl /usr/local/bin/grep searchd
and kill it
$kill -9 49630
Voila!

Friday, November 2, 2012

Is there a way through which I see which mysql queries are fired from ActiveRecord in rails console?

http://stackoverflow.com/questions/4667316/how-to-see-mysql-queries-in-rails-console

Yes, this can be achieved through redirecting rails log to standard output.

Write these at your console prompt:

ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.connection_pool.clear_reloadable_connections!
Furthermore, you can put these lines in ~/.irbrc file, so that each time you don't need to manually write these 2 lines:

require 'rubygems'

if ENV.include?('RAILS_ENV') && ENV["RAILS_ENV"] == 'development'
    ActiveRecord::Base.logger = Logger.new(STDOUT)
    ActiveRecord::Base.connection_pool.clear_reloadable_connections!
end