概要 原著者の許諾を得て翻訳・公開いたします。 英語記事: Avoid Writing SQL When Using ActiveRelation - Andy Croll 原文公開日: 2018/02/18 著者: Andy Croll 訳注: 原文のActiveRelationは訳文でActiveRecord::Relationに変更してあります。 ActiveRecord::Relationは、ActiveRecordの検索やクエリエンジンを強化する、柔軟で強力なツールです。 次のようには書かないこと ActiveRecord::Relationの#whereメソッド内で生SQL文字列を式展開(interpolation)で直接書く。 Person.where("name = #{ params[:name] } AND hidden_at IS NULL") これもやらないこと ?
![Rails: ActiveRecord::Relationで生SQLは避けよう(翻訳)|TechRacho by BPS株式会社](https://cdn-ak-scissors.b.st-hatena.com/image/square/e7cb9c770413af17c726ca294ab2ef1248a51cdc/height=288;version=1;width=512/https%3A%2F%2Ftechracho.bpsinc.jp%2Fwp-content%2Fuploads%2F2018%2F05%2Frails_avoid_writing_sql_on_activerelation_eyecatch.png)