English 中文(简体)
B. RoR3 观点中的接触变量
原标题:Access variables dynamically in views on RoR3

我有10个实例变量,即:@foo_01, @foo_02, @foo_03, @foo_10, 并且我需要在一个页上显示每个变量的成因,这些结果必须用一个相当长的算法加以展示,我不会复制,过去10次改变变量名称,因为我发现这种说法极其令人厌恶,因此我looking想一种途径,通过算法10次循环,并动态地获取变量,例如这种变数。

<% (1..10).each do |i| %>
  <% lengthy algorithm here %>
    <%= @foo_i .atribute.value %>
  <% end %>
<% end %>
问题回答

t能成为一阵列,有十个要素? 然后,您可随附@foo.each





相关问题
passing form variables into a url with php

I have the following form which allows a user to select dates/rooms for a hotel reservation. <form action="booking-form.php" method="post"> <fieldset> <div class="select-date">...

Error: "Cannot modify the return value" c#

I m using auto-implemented properties. I guess the fastest way to fix following is to declare my own backing variable? public Point Origin { get; set; } Origin.X = 10; // fails with CS1612 Error ...

C-style Variable initialization in PHP

Is there such a thing as local, private, static and public variables in PHP? If so, can you give samples of each and how their scope is demonstrated inside and outside the class and inside functions?

C#/.NET app doesn t recognize Environment Var Change (PATH)

In my C# app, I am programmatically installing an Oracle client if one is not present, which requires adding a dir to the PATH system environment variable. This all works fine, but it doesn t take ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

How to dynamically generate variables in Action Script 2.0

I have a for loop in action script which I m trying to use to dynamically create variable. Example for( i = 0 ; i &lt 3 ; i++) { var MyVar+i = i; } after this for loop runs, i would like to ...

热门标签