검색결과 리스트
글
액션뷰 (기본도우미 메소드)
IT(Old)/RubyOnRails
2008. 1. 22. 11:43
숫자 및 텍스트를 포맷하는 도우미 메소드
- number_with_delimiter(num(숫자에서 세자리마다 쉼표를 찍어줌)
<%= number_woth_Delimiter(1562000) %>
=> 1,562,000
- number_with_precision(num, digits): 소수를 표시할 때, 소수점 이하 자리수를 제한하여 표시해줌, 두 번째 인자는 소수점 이하 자리수를 지정함. 두 번째 인자는 선택사항으로 지정하지 않으면 소수점이 세 자리까지 표시됨
<% number_with_precision(200.0, 1 %>
=> 66.7
<% number_With_precision(200.0/3) %>
=> 66.667
- number_to_human_size(num) : 숫자를 바이트로 계산하여, 사람이 읽기 편한 단위(Byte, KB, MB등)로 변환해줌
<%= number_to_human_size(31270) %>
=> 30.5KB
- truncate(str,length) : 전체 문자열의 길이가 length를 넘지 않도록 str의 끝을 잘라줌
<%= truncate("무궁화 꽃이 피었습니다", 10) %>
=> 무궁화 꽃이 ...
- highlight(str, word): str안의 텍스트에서 word로 넘겨받은 문자열이 나타날 때마다 <strong> 태그를 사용하여 강조해줌
<%= highlight("무궁화 꽃이 피었습니다.", "꽃") %>
=> 무궁화 <strong class=highlight">꽃</strong>이 피었습니다.
- simple_format(str) : 텍스트를 HTML로 변환
이미지 태그 도우미 메소드
- image_tag(source, html_options): <img> 태그를 출력해줌, html_options 부분은 해시로 데이터를 전달받으며, :size, :class, :alt 옵션 등을 사용할 수 있다.
<%= image_tag("company_logo.gif", :size => "80x30",
:class => "logo",
:alt => "회사 로고") %>
<img src="/images/company_logo.gif" class="logo" width="80" height="30" alt="회사 로고" />
링크 도우미 메소드
- link_to(name, options, html_options) :<a>태그를 출력해줌. options 부분은 해시로 데이터를 전달받으며, :controller, :action, :id등 해당 라우팅의 URL패턴에 사용되는 모든 요소를 옵션으로 사용할 수 있다. html_options부분은 <a>태그에서 사용되는 html옵션을 해시로 전달받으며, :class, :popup, :confirm, :method등을 사용할 수 있다.
<%= link_to("프로필 보기",
{:controller => "users", :action => "show", :id => @user},
{:popup => ['Help', 'width=320, height=400'], :class => "info"}) %>
=>
<a href="/users/show/41" class="info" onclick="window.open(this.href, '프로필','width=320, height=400');
return false;">프로필 보기 </a>
- number_with_delimiter(num(숫자에서 세자리마다 쉼표를 찍어줌)
<%= number_woth_Delimiter(1562000) %>
=> 1,562,000
- number_with_precision(num, digits): 소수를 표시할 때, 소수점 이하 자리수를 제한하여 표시해줌, 두 번째 인자는 소수점 이하 자리수를 지정함. 두 번째 인자는 선택사항으로 지정하지 않으면 소수점이 세 자리까지 표시됨
<% number_with_precision(200.0, 1 %>
=> 66.7
<% number_With_precision(200.0/3) %>
=> 66.667
- number_to_human_size(num) : 숫자를 바이트로 계산하여, 사람이 읽기 편한 단위(Byte, KB, MB등)로 변환해줌
<%= number_to_human_size(31270) %>
=> 30.5KB
- truncate(str,length) : 전체 문자열의 길이가 length를 넘지 않도록 str의 끝을 잘라줌
<%= truncate("무궁화 꽃이 피었습니다", 10) %>
=> 무궁화 꽃이 ...
- highlight(str, word): str안의 텍스트에서 word로 넘겨받은 문자열이 나타날 때마다 <strong> 태그를 사용하여 강조해줌
<%= highlight("무궁화 꽃이 피었습니다.", "꽃") %>
=> 무궁화 <strong class=highlight">꽃</strong>이 피었습니다.
- simple_format(str) : 텍스트를 HTML로 변환
이미지 태그 도우미 메소드
- image_tag(source, html_options): <img> 태그를 출력해줌, html_options 부분은 해시로 데이터를 전달받으며, :size, :class, :alt 옵션 등을 사용할 수 있다.
<%= image_tag("company_logo.gif", :size => "80x30",
:class => "logo",
:alt => "회사 로고") %>
<img src="/images/company_logo.gif" class="logo" width="80" height="30" alt="회사 로고" />
링크 도우미 메소드
- link_to(name, options, html_options) :<a>태그를 출력해줌. options 부분은 해시로 데이터를 전달받으며, :controller, :action, :id등 해당 라우팅의 URL패턴에 사용되는 모든 요소를 옵션으로 사용할 수 있다. html_options부분은 <a>태그에서 사용되는 html옵션을 해시로 전달받으며, :class, :popup, :confirm, :method등을 사용할 수 있다.
<%= link_to("프로필 보기",
{:controller => "users", :action => "show", :id => @user},
{:popup => ['Help', 'width=320, height=400'], :class => "info"}) %>
=>
<a href="/users/show/41" class="info" onclick="window.open(this.href, '프로필','width=320, height=400');
return false;">프로필 보기 </a>