Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
Ruby on rails Rails 4:使用变量渲染局部_Ruby On Rails_Partial Views_Partials - Fatal编程技术网

Ruby on rails Rails 4:使用变量渲染局部

Ruby on rails Rails 4:使用变量渲染局部,ruby-on-rails,partial-views,partials,Ruby On Rails,Partial Views,Partials,我有以下几点意见: <tr class="profile-row"> <td class="profile-header"><%= attribute %></td> <% for week in @weeks %> <td><%= week.<%= field %> %></td> <!-- where it fails --> <% e

我有以下几点意见:

<tr class="profile-row">
    <td class="profile-header"><%= attribute %></td>
    <% for week in @weeks %>
    <td><%= week.<%= field %> %></td> <!-- where it fails -->
    <% end %>
</tr>
…我想要:

<tr class="profile-row">
    <td class="profile-header">Current Weight</td>
    <% for week in @weeks %>
    <td><%= week.current_weight %></td> <!-- where it fails -->
    <% end %>
</tr>

当前重量

…但此操作失败,出现
语法错误、意外的tOP\u ASGN…
。我知道这不是提供变量的正确方法,但是我应该怎么做呢

不能像这样嵌套ERB标记:

<%= week.<%= field %> %>

不能像这样嵌套ERB标记:

<%= week.<%= field %> %>
不能嵌套erb标记。 如果变量是字符串,则可以将它们连接起来

<%= week + "." + field%>

如果出现错误,请尝试此操作

<%= week.to_s + "." + field.to_s%>

不能嵌套erb标记。 如果变量是字符串,则可以将它们连接起来

<%= week + "." + field%>

如果出现错误,请尝试此操作

<%= week.to_s + "." + field.to_s%>