I'm trying to have the slug length be less than 20 if the key_type
is 4
.
In the model I have
validate :text_slug_length
def text_slug_length
if key_type == 4
slug.slice(0, 19)
end
end
But this doesn't throw any errors but also doesnt work. Not sure why...
The slug isnt used for values that have a key_type
of 4
. Data with the key_type
of 4
can be long slabs of text so it causes length errors when its trying to save a really long slug. I could somehow not save a slug of the key_type
4
but this way will also stop the errors from long slugs being generated and I figured .slice
would be easier.
Can someone help on why this doesn't work.