当用户提交表单并将某些字段留空时,它们将在数据库中保存为空白.我想遍历params [:user]集合(例如),如果字段为空,则在更新属性之前将其设置为nil.我无法弄清楚如何做到这一点,因为我知道迭代的唯一方法是创建新对象:
coll = params[:user].each do |c| if c == "" c = nil end end
谢谢.
ruby forms collections ruby-on-rails
collections ×1
forms ×1
ruby ×1
ruby-on-rails ×1