相关疑难解决方法(0)

使空白参数[]为零

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

coll = params[:user].each do |c|
    if c == ""
       c = nil
    end
end
Run Code Online (Sandbox Code Playgroud)

谢谢.

ruby forms collections ruby-on-rails

31
推荐指数
3
解决办法
2万
查看次数

标签 统计

collections ×1

forms ×1

ruby ×1

ruby-on-rails ×1