Almost solved the problem myself. Since the Message model in my body field is encrypted in AES I rewrote the method to_param body - a cipher text like wuTekBX7p0K+olP6Vd/8Jw==$okRXvvSB1ZRRuhxF3O9EIg== .
def to_param "#{id}-#{body.tr('^A-Za-z0-9', '')[0..12].insert(3, self.id.to_s.chars.each_slice(2).map(&:join).first).insert(9, self.id.to_s.chars.each_slice(2).map(&:join).last).parameterize}" end Yes, it looks a bit strange :)
In the end, the link is obtained /messages/2-wut2ekbx72p0kol But you need to do without the id in the beginning and so that it is unique.
idinto the table. - Alex Chermenin