Doing a `join` on an array containing html safe strings will produce an html unsafe string.
Rails provides a helper called `safe_join` that will always produce an html safe string.
This gem modifies `Array#join` so that it returns an html safe string when the first element is an html safe string. This is similar to `s1 + s2` returning an html safe string if and only if `s1` is html safe. If the first element is not an html safe string (or does not exist), then `Array#join` returns a normal string, as was previously the case. Again, this is similar to `s1 + s2` returning a normal string if `s1` is a normal string, even if `s2` is an html safe string.
links = [link_to("Home", "/"), link_to("Profile", "/profile")] desired = links + " > " + links joined = links.join(" > ") joined == desired # => false joined.html_safe? # => false require 'rails_join' joined = links.join(" > ") joined == desired # => true joined.html_safe? # => true
Simply add to your Gemfile:
Run `bundle install` and you're done.
Runs on all versions of Ruby and all versions of Rails >= 3.0
Copyright © 2012 Marc-Andre Lafortune. See LICENSE.txt for further details.