As you are on rails 4.2.5, you can use https://github.com/rails/rails-html-sanitizer which gets installed with rails. You can do following to escape only script tag.
scrubber = Rails::Html::TargetScrubber.new
scrubber.tags = ['script']
html_fragment = Loofah.fragment('<script></script><div></div>')
html_fragment.scrub!(scrubber)
html_fragment.to_s # outputs "<div></div>"