I have this code in my every model.
Class people
def before_validation
@attributes.each do |key,value|
self[key] = nil if value.blank?
end
end
end
Now i want to put my loop in separate module. Like
Module test
def before_validation
@attributes.each do |key,value|
self[key] = nil if value.blank?
end
end
end
And i want to call this before_validation this way
Class people
include test
def before_validation
super
.....Here is my other logic part.....
end
end
Are there any way to do it like that in rails??
I have this code in my every model. Class people def before_validation @attributes.each do
Share
You can setup multiple methods to be called by the before_validation callback. So instead of straight up defining the before_validation, you can pass the methods you want to get called before validation.
You can read more about callbacks here: http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html