[英]How can I specify attributes to use in update_attributes in ROR3?
我想要实现的是只更新我的Order模型中的可访问属性,传递current_user对象,如下所示:
order.update_attributes(current_user.attributes.ONLY(:name, :surname, :email))
那么有可能在没有明确设置要更新的列的情况下实现这一点吗?
使用Rails中的Hash#slice :
current_user.attributes.slice(:name, :surname, :email)
您可以使用Hash#select
,如下例所示:
current_user.attributes.select{|key, _| [:name, surname, email].include?(key)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.