Table.update_all也可以用:conditions


文档:

update_all(updates, conditions = nil, options = {}) 




例子:

Billing.update_all( "author = 'David'", "title LIKE '%Rails%'" )
/*
mysql > update billings set author = 'David' where title LIKE '%Rails%';
*/


也可以这样写:
author = 'David'
title = 'Rails'
Billing.update_all(["author = ?", author], ["title like ?", "%#{title}%"])


也是可以传变量的喔。这样写安全些。

你可能感兴趣的:(mysql,Ruby,Rails)