2016-07-07 121 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 %> 
相关问题