SQL log in Rails console


/ Published in: Rails
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # for rails 2
  2. if ENV.include?('RAILS_ENV')
  3. if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
  4. require 'logger'
  5. Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
  6. end
  7.  
  8. def sql(query)
  9. ActiveRecord::Base.connection.select_all(query)
  10. end
  11. # for rails 3
  12. elsif defined?(Rails) && !Rails.env.nil?
  13. if Rails.logger
  14. Rails.logger = Logger.new(STDOUT)
  15. ActiveRecord::Base.logger = Rails.logger
  16. end
  17. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.