Read more

Retrieve the SQL query a scope would produce in ActiveRecord

Henning Koch
April 07, 2011Software engineer at makandra GmbH

Rails 3

User.active.to_sql

Rails 2

Use either the Edge Rider Show archive.org snapshot or fake_arel Show archive.org snapshot gem to get #to_sql backported to Rails 2.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

If you don't want to use a gem for this, you can do this with vanilla Rails 2:

User.active.construct_finder_sql({})
Posted by Henning Koch to makandra dev (2011-04-07 18:09)