How to view the converted sql from Activerecord method in view

A

Arun Kumar

Hi All,

I will be happy if someone clear doubt, i can see objects in view by
using <%= debug @object %> and lot of methods is there apart from view
like
to_yml, etc

Is there any method available for seeing the converted sql from
ActiveRecord method in view, etc. Although I can find it in console but
it will confuse when we run multiple queries..

example:

User.find :all

it will produce

"SELECT * FROM users;"

in output console

But i want it in view are any other specific point like yml , etc ?


Thanks,
Jak
 
W

Walton Hoops

Hi All,

I will be happy if someone clear doubt, i can see objects in view by
using<%= debug @object %> and lot of methods is there apart from view
like
.to_yml, etc

Is there any method available for seeing the converted sql from
ActiveRecord method in view, etc. Although I can find it in console but
it will confuse when we run multiple queries..

example:

User.find :all

it will produce

"SELECT * FROM users;"

in output console

But i want it in view are any other specific point like yml , etc ?
This is really a Rails question and should go on the Rails list. That
said, the console just prints the the results from .inspect on whatever
was returned by the last statement, so you should just be able to use
User.find:)all).inspect.
 
B

Brian Candler

Arun Kumar wrote in post #972531:
Is there any method available for seeing the converted sql from
ActiveRecord method in view, etc. Although I can find it in console but
it will confuse when we run multiple queries..

If I google for "activerecord sql log", the first hit shows how to
install a custom logger for ActiveRecord.
 
A

Arun Kumar

Hi All,

Thanks for quick replies
We can also use to_sql method in rails 3

User.where:)name => :jak).to_sql # => "SELECT `users`.* FROM `users`
WHERE (`users`.`name` = 'jak')"

We can render that into a view or anywhere else we like.

Thanks
jak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top