Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用content_标记在rubyonrails中构建HTML表_Html_Ruby On Rails_Ruby_Html Table_Content Tag - Fatal编程技术网

使用content_标记在rubyonrails中构建HTML表

使用content_标记在rubyonrails中构建HTML表,html,ruby-on-rails,ruby,html-table,content-tag,Html,Ruby On Rails,Ruby,Html Table,Content Tag,我正试图借助content_标记方法在RubyonRails中构建一个html表 例如: @template.content_tag(:tr, @template.content_tag(:td, options[:argument0])) 这应该会导致 <tr><td>content of argument0</td></tr> argument0的内容 我需要的是 <tr><td>content of argume

我正试图借助content_标记方法在RubyonRails中构建一个html表

例如:

@template.content_tag(:tr, @template.content_tag(:td, options[:argument0]))
这应该会导致

<tr><td>content of argument0</td></tr>
argument0的内容
我需要的是

<tr><td>content of argument0</td><td>argument1</td> ... </tr>
argument0argument1的内容。。。

我可以用同样的方法构建它吗?如何传递两个内容标签

您可以使用
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)

您可以使用
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)