I have 2 models using 2 similar methods. Both of them called are generate
and both are called by before_save
. I want to refactor them into one. How can I do that?
#model1's generate
before_save :generate
def generate
self.slug = self.title.gsub(' ', '-').downcase
end
#model2‘s generate
before_save :generate
def generate
self.slug = self.name.gsub(' ', '-').downcase
end