【发布时间】:2016-04-23 00:57:27
【问题描述】:
我有以下部分:
<tr class="profile-row">
<td class="profile-header"><%= attribute %></td>
<% for week in @weeks %>
<td><%= week.<%= field %> %></td> <!-- where it fails -->
<% end %>
</tr>
...我希望能够提供 2 个变量,attribute 和 field。当我尝试使用以下内容渲染部分时:
<%= render 'foo', attribute: 'Current Weight', field: 'current_weight' %>
...我想要:
<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>
...但这会因syntax error, unexpected tOP_ASGN... 而失败。我知道这不是提供变量的正确方法,但我应该怎么做呢?
【问题讨论】:
标签: ruby-on-rails partial-views partials