调试Rails活动记录查询

Jar*_*ipp 2 activerecord ruby-on-rails

有没有办法在执行之前调试ActiveRecord查询而不是之后?

Mat*_*ner 11

您可以在查询结束时调用.to_sql来输出它生成的sql,如下所示:

SomeModel.where(:stuff => 'is here').to_sql
Run Code Online (Sandbox Code Playgroud)