I have the following code that works but Im slightly confused as to why.
before_save :generate_slug
def generate_slug
self.slug = [id, title.to_url].join('-')
end
I was under the impression that using self
on a model method would be a Class method whereas this information is clearly being saved to an Instance, is this correct?
If I remove self
from the self.slug
the method doesn't work and slug
is nil
.
So if I need self.slug
for the method to work should be using self
on self.id
& self.title.to_url
as well?