This page is not available in every language. Missing translations are disabled in the language selector.

Quick reference

Rails View Helpers Cheatsheet

A quick reference guide for Rails built-in view helpers: numbers, currency, human dates, strings, sanitization, and asset tags.

· Published

Action View helpers provide clean formatting methods for text, numbers, dates, and media assets inside template views.

Number & Currency Helpers

<%= number_to_currency(1234.56) %>
<!-- => "$1,234.56" -->

<%= number_to_currency(1234.56, unit: "€", format: "%u %n") %>
<!-- => "€ 1,234.56" -->

<%= number_to_percentage(85.4, precision: 1) %>
<!-- => "85.4%" -->

<%= number_to_human_size(15485863) %>
<!-- => "14.8 MB" -->

<%= number_with_delimiter(12345678) %>
<!-- => "12,345,678" -->

Date & Time Helpers

<!-- Human readable relative time -->
<%= distance_of_time_in_words(Time.now, 3.hours.from_now) %>
<!-- => "about 3 hours" -->

<%= time_ago_in_words(user.created_at) %>
<!-- => "3 days ago" -->

<!-- Semantic HTML5 <time> tag -->
<%= time_tag(article.published_at) %>
<!-- => '<time datetime="2026-10-25T00:00:00Z">October 25, 2026</time>' -->

Text & String Helpers

<%= truncate("The quick brown fox jumps over the lazy dog", length: 20) %>
<!-- => "The quick brown f..." -->

<%= pluralize(3, "comment") %>
<!-- => "3 comments" -->

<%= pluralize(1, "comment") %>
<!-- => "1 comment" -->

<%= highlight("Text with keywords highlighted", "keywords") %>
<!-- => 'Text with <mark>keywords</mark> highlighted' -->

<%= simple_format("Paragraph 1

Paragraph 2") %>
<!-- => "<p>Paragraph 1</p><p>Paragraph 2</p>" -->

Asset & Tag Helpers

<%= link_to "Profile", user_path(@user), class: "nav-link" %>
<%= button_to "Delete", user_path(@user), method: :delete, data: { turbo_confirm: "Are you sure?" } %>
<%= image_tag "avatar.png", alt: "User Avatar", size: "64x64" %>

References

Related topics