A
A
Aaron Besov2016-09-07 08:38:04
PostgreSQL
Aaron Besov, 2016-09-07 08:38:04

How to write SQL queries to the database in Rails, to a separate file?

Good afternoon. In my rail project, it became necessary to write sql queries to the database, in a separate file. All requests are written to the railsav log file, but absolutely everything is written there. I'm not so comfortable.
Has anyone done this, any ideas?

Answer the question

In order to leave comments, you need to log in

3 answer(s)

Write your own logger
ruby-doc.org/stdlib-2.0.0/libdoc/logger/rdoc/Logge...

K
Karim Kyatlottyavi, 2016-09-09
@constXife

I'll expand on the above answer a bit.
guides.rubyonrails.org/configuring.html
For example, in order to log SQL queries to a file, you need to write such a line, for example, in config/application.rb.

config.active_record.logger = Logger.new(Rails.root.join('log', 'sql.log'))

N
Nikolai Turnaviotov, 2016-10-03
@foxmuldercp

in general, in dev mode, queries to the database and so are written to the log

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question