尝试将变量放入:condition语句。
user = User.all(:conditions => 'confirmed_at is NULL AND
confirmation_sent_at <= DATE_SUB(NOW(), INTERVAL X day)')
如何在X日部分注入变量? 我尝试了proc块并转发+常规但都失败了
答案 0 :(得分:1)
根据文档: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)