빠른 참조

Rails 뷰 헬퍼 치트시트

Rails 내장 뷰 헬퍼 빠른 참조 가이드: 숫자, 통화, 상대적 날짜, 문자열 포맷팅, 새니타이징 및 에셋 태그.

· 게시일

Action View 헬퍼는 템플릿 뷰 내에서 텍스트, 숫자, 날짜 및 미디어 자산을 깔끔하게 서식화하는 메서드를 제공합니다.

숫자 및 통화 헬퍼

<%= 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" -->

날짜 및 시간 헬퍼

<!-- 사람이 읽기 쉬운 상대 시간 -->
<%= distance_of_time_in_words(Time.now, 3.hours.from_now) %>
<!-- => "about 3 hours" -->

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

<!-- 시맨틱 HTML5 <time> 태그 -->
<%= time_tag(article.published_at) %>
<!-- => '<time datetime="2026-10-25T00:00:00Z">October 25, 2026</time>' -->

텍스트 및 문자열 헬퍼

<%= 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>" -->

에셋 및 태그 헬퍼

<%= 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" %>

참고 자료

관련 주제