0.0
No commit activity in last 3 years
No release in over 3 years
Conditionally nullify attributes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 6.0, >= 3.0
< 6.0, >= 3.0
 Project Readme

Conditionally nullify attributes.

Gem Version

About

Allows to conditionally (supports both if and unless) nullify attributes in before_validation hook.

Usage

class Post < ActiveRecord::Base
  # Store description as NULL when description is blank.
  nullify :description, unless: :description?
end

class Payment < ActiveRecord::Base
  # We don't want to store bank card vendor when payment method isn't bank card.
  nullify :bank_card_vendor, unless: :paid_using_bank_card?
end

Installing gem

Add to your Gemfile:

gem 'nullify-attr', '~> 1.0'