From 5c6d40c18a0ffe05ef2ecf2eb09ad1d0f5e0f017 Mon Sep 17 00:00:00 2001 From: Ari Timonen Date: Fri, 10 Apr 2020 19:58:57 +0300 Subject: [PATCH] Add cleanup function --- app/models/concerns/extra.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/concerns/extra.rb b/app/models/concerns/extra.rb index b10d692..cfbf43a 100644 --- a/app/models/concerns/extra.rb +++ b/app/models/concerns/extra.rb @@ -29,6 +29,14 @@ module Extra Sanitize.clean(text.to_s).bbcode_to_html.gsub(/\n|\r\n/, "
").html_safe end + def cleanup_string(str, len=20) + str = str.gsub(/[^0-9A-Za-z\-_]/, '') + if str.length > len + str = str.to_s[0, len] + end + return str + end + def move_up(objects, column = "position") n = 0 # the objects need to be assigned before loop or the order is not right