Make blank params[] nil

前端 未结 13 597
半阙折子戏
半阙折子戏 2020-12-13 18:36

When a user submits a form and leaves certain fields blank, they get saved as blank in the DB. I would like to iterate through the params[:user] collection (for example) an

13条回答
  •  囚心锁ツ
    2020-12-13 18:47

    A good gem for handling this in the model: https://github.com/rmm5t/strip_attributes

    It defines a before_validation hook that trims whitespaces and sets empty strings to nil.

提交回复
热议问题