What is validation ? Validations are required for ensuring that the received data is correct and valid. If the received data is valid then we do the further processing with the data. Nested Model Validation Nested model is sometimes tricky when you have complex associations. Here I'm explaining how we can do nested model validation. We use nested form to save associations through its parent model. Generally we do: class Album < ActiveRecord::Base has_many :songs accepts_nested_attributes_for :songs end When we are using nested form we want to save a new or edit an existing album with songs. Now suppose we want all the songs to be removed on removal of the album. class Album < ActiveRecord::Base has_many :songs accepts_nested_attributes_for :songs, :allow_destroy => true end At this point we can detect and reject empty association entries class Album < ActiveRecord::Base ...
This blog is a note about interesting tech and topics covered by me