2012-12-06 1 views
0

나는 content_tag 메소드의 도움으로 Ruby On Rails에서 html 테이블을 만들려고합니다.ruby ​​on the content_tag를 사용하여 레일스에서 ​​HTML 테이블 만들기

예 :

<tr><td>content of argument0</td><td>argument1</td> ... </tr> 

같은 나는이 같은 방법으로 만들 수

@template.content_tag(:tr, @template.content_tag(:td, options[:argument0])) 

<tr><td>content of argument0</td></tr> 

에 렌더링해야 내가 필요한 것은? 두 개의 content_tags를 전달하려면 어떻게해야합니까?

답변

2

당신은 concat 사용할 수 있습니다

@template.content_tag(:tr, 
    @template.content_tag(:td, options[:argument0]). 
    concat(@template.content_tag(:td, options[:argument1])). 
    concat(@template.content_tag(:td, options[:argument2])) 
    # .... 
) 

또는 루프를 사용 - 영업 이익은 코멘트에 제안

rows = returning "" do |cells| 
    5.times do |i| 
    cells.concat @template.content_tag(:td, options["argument#{i}".to_sym] 
    end 
end 
@template.content_tag(:tr,rows)