2016-07-07 98 views
-1

如何在rails上渲染html x次?ruby​​ on rails - 如何渲染html x次

目前我有什麼<%= for i in 1..5 do render html:"X" end %>

但這使得1..3

我怎樣才能使它呈現XXX?我究竟做錯了什麼?

+0

「呈現1..3」是什麼意思? –

回答

0

如何:

# x would be the number of times to render this html 
<% x.times do %> 
    <%= render html: 'X' %> 
<% end %> 

不知道爲什麼你這樣做,但是,堆棧溢出的社會也許能提供一個更好的方法。

+1

爲什麼不只是5次呢,它會簡化你的答案... – Agush

+0

哇!有效!對不起,我在RoR是全新的,那是什麼? – broshen

+0

也是,爲什麼會這樣,但是<%= x.times do render html:'X'end%> does not? – broshen

0

你試過嗎?

<% (1..5).each do |i| %> 
    <%= render html: "X" %> 
<% end %>