Rails 문자열, 숫자 관련 뷰 헬퍼3
숫자를 가공 하기
number_to_currentcy(num)
메소드
number_to_human(num)
메소드
number_to_human_size(num)
메소드
number_to_percentage(num)
메소드
number_with_delimiter(num)
메소드
number_with_precision(num)
메소드
날짜 형식 포맷팅 하기
strftime(format)
메소드
<%= Time.now.strftime('%Y년 %m월 %d일 %H시 %M분 %S초 입니다.') %>
아래처럼 하면 기본 포맷으로 간단하게 변환 가능 하다.
<%= Time.now.strftime('%F %T') %>
링크 만들기
link_to(body, url)
메소드
<%= link_to '여기를 클릭', 'http://google.com' %>
<%= link_to '여기를 클릭', 'http://google.com', id: :link_id, class: :link_class %>
url_for
메소드
<a>
링크가 아니라 경로의 문자열이다. (route.rb 기반)<%= url_for(controller: :post, action: :show, id: 5 %>
<%= url_for(:back) %>
link_to_if
, link_to_unless
메소드: 조건에 따라 링크를 만든다.
link_to_unless_current
메소드 : 생성 할려는 링크가 현재 페이지라면 링크 대신 문자열만 출력한다 (무효화), 메뉴 등에 사용 하면 용이하다.
mail_to
메소드 : 지정된 메일 주소로 mailto: 링크를 생성 한다.
<%= mail_to 'test@gmail.com', subject: '제목', cc: 'test2@gmail.com' %>