试图将变量放入 :condition 语句。
user = User.all(:conditions => 'confirmed_at is NULL AND
confirmation_sent_at <= DATE_SUB(NOW(), INTERVAL X day)')
如何在 X 日部分注入变量?我尝试了 proc 块和转义 + 常规但都失败了
试图将变量放入 :condition 语句。
user = User.all(:conditions => 'confirmed_at is NULL AND
confirmation_sent_at <= DATE_SUB(NOW(), INTERVAL X day)')
如何在 X 日部分注入变量?我尝试了 proc 块和转义 + 常规但都失败了
根据文档: http: //guides.rubyonrails.org/active_record_querying.html#array-conditions
您应该能够执行以下操作:
User.where('confirmed_at is NULL AND confirmation_sent_at <= DATE_SUB(NOW(), INTERVAL ? day)', your_variable)