Type:
Module

The TextHelper module provides a set of methods for filtering, formatting and transforming strings, which can reduce the amount of inline Ruby code in your views. These helper methods extend Action View making them callable within your template files.

Sanitization

Most text helpers by default sanitize the given content, but do not escape it. This means HTML tags will appear in the page but all malicious code will be removed. Let's look at some examples using the simple_format method:

simple_format('<a href="http://example.com/">Example</a>')
# => "<p><a href=\"http://example.com/\">Example</a></p>"

simple_format('<a href="javascript:alert(\'no!\')">Example</a>')
# => "<p><a>Example</a></p>"

If you want to escape all content, you should invoke the h method before calling the text helper.

simple_format h('<a href="http://example.com/">Example</a>')
# => "<p>&lt;a href=\"http://example.com/\"&gt;Example&lt;/a&gt;</p>"
current_cycle

current_cycle(name = "default") Instance Public methods Returns the current

2015-06-20 00:00:00
word_wrap

word_wrap(text, options = {}) Instance Public methods Wraps the text

2015-06-20 00:00:00
cycle

cycle(first_value, *values) Instance Public methods Creates a Cycle object whose

2015-06-20 00:00:00
highlight

highlight(text, phrases, options = {}) Instance Public methods Highlights one

2015-06-20 00:00:00
concat

concat(string) Instance Public methods The preferred method of outputting text

2015-06-20 00:00:00
simple_format

simple_format(text, html_options = {}, options = {}) Instance Public methods Returns

2015-06-20 00:00:00
excerpt

excerpt(text, phrase, options = {}) Instance Public methods Extracts an excerpt

2015-06-20 00:00:00
truncate

truncate(text, options = {}, &block) Instance Public methods Truncates a

2015-06-20 00:00:00
reset_cycle

reset_cycle(name = "default") Instance Public methods Resets a cycle so that

2015-06-20 00:00:00
safe_concat

safe_concat(string) Instance Public methods

2015-06-20 00:00:00