Ruby on rails 时间循环不起作用
我为rails应用程序编写了一个简单的助手:Ruby on rails 时间循环不起作用,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我为rails应用程序编写了一个简单的助手: def calendar_build 5.times do whole_cal end end def whole_cal content_tag(:div, :class => "row") do small_cal + big_cal end end def small_cal content_tag(:div, :class => "c
def calendar_build
5.times do
whole_cal
end
end
def whole_cal
content_tag(:div, :class => "row") do
small_cal + big_cal
end
end
def small_cal
content_tag(:div, :class => "col-xs-2 token-text") do
concat(content_tag(:p, "15.20"))
end
end
def big_cal
content_tag(:div, :class => "col-xs-10 weite_cal") do
concat(content_tag(:input,"", class: "form-control input-sm pa"))
end
end
您可以看到我如何尝试生成5个完整的\u cal
:
def calendar_build
5.times do
whole_cal
end
end
但在我看来,这只显示
5
为什么?谢谢您必须将生成的html代码添加到类似于result的变量中,然后将result作为方法的最后一行返回连接的代码
比如:
result = ""
5.times do
result += html code
end
result
根据您的html代码,您应该将最后一行替换为result.html\u safe循环的返回值为5
1.9.3p194 :056 > 5.times {}
=> 5
你也许应该这样做
def calendar_build
whole_cals = []
5.times do
whole_cals << whole_cal
end
whole_cals
end
def日历\u构建
整个_cals=[]
5.5倍
整盘你不能做整盘*5
?字符串乘法通常是有效的。这会将数组中的整个代码返回到视图,而不是以html[“1