Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off verbose sql/ActiveRecord for Rails 3.1.1

Tags:

Whereas the verbose feature of SQL/ActiveRecord calls is useful most of the time, I would like to turn it off in cases where I have some looping going on.

Is there a way to turn it off?

irb(main):055:0> City.first   ←[1m←[35mCity Load (1.0ms)←[0m  SELECT `cities`.* FROM `cities` LIMIT 1 => #<City id: 1, name: "bla bla", state_id: 1, zip: nil, country_id: nil, created_at: "2011-03-27 14:11:28", updated_at: "2011-08-16 11:14:36", guid: "5PK fvvz2Gsi"> 
like image 469
Abdo Avatar asked Nov 01 '11 13:11

Abdo


People also ask

What is ActiveRecord in Ruby on Rails?

Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.

Can you use ActiveRecord without rails?

One of the primary aspects of ActiveRecord is that there is very little to no configuration needed. It follow convention over configuration. ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.

What does ActiveRecord base do?

ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.

Is ActiveRecord an ORM?

ActiveRecord is an ORM. It's a layer of Ruby code that runs between your database and your logic code. When you need to make changes to the database, you'll write Ruby code, and then run "migrations" which makes the actual changes to the database.


2 Answers

In console:
Disable:

old_logger = ActiveRecord::Base.logger ActiveRecord::Base.logger = nil 

Enable:

ActiveRecord::Base.logger = old_logger 
like image 70
Mikhail Nikalyukin Avatar answered Nov 17 '22 20:11

Mikhail Nikalyukin


In Rails 4 I've been annoyed by ActiveRecord logging SQL statements in the middle of my specs so I disable it by adding this to config/environments/test.rb:

Rails.application.configure do   # ...    config.log_level = :info end 
like image 33
drewish Avatar answered Nov 17 '22 21:11

drewish