Ruby on rails 如何在Rails中使用espinta迭代多个哈希值
我使用它来跟踪对模型的更改,并有多个属性要显示在视图中 我还没有弄清楚如何在迭代器中不使用Ruby on rails 如何在Rails中使用espinta迭代多个哈希值,ruby-on-rails,ruby,Ruby On Rails,Ruby,我使用它来跟踪对模型的更改,并有多个属性要显示在视图中 我还没有弄清楚如何在迭代器中不使用| |迭代每个值。我想获取属性名、更改的值和日期 这是show.html: <% @contract.contract_information.history_from_audits_for([:contract_title, :assigned_to, :action_requested..:deadline]).each do |changes| %> <tr> <%
| |
迭代每个值。我想获取属性名、更改的值和日期
这是show.html:
<% @contract.contract_information.history_from_audits_for([:contract_title, :assigned_to, :action_requested..:deadline]).each do |changes| %>
<tr>
<%= changes[:contract_title] || changes[:assigned_to] || changes[:deadline] %>
<%= changes[:changed_at].strftime("%m/%d/%Y") %>
</tr>
<% end %>
看法
如果您有机会在项目中更新Espinta,我建议您这样做,因为
历史记录\u从
的审计\u返回哈希值
在较新版本中,您将在“”文档中看到类似的内容:
model.history\u来自([:name,:settings])
=>,
{:changes=>{:name=>“Arglebargle”,:settings=>“IHOP”},:changed_at=>2015-03-2415:33:58-0700},
{:changes=>{:name=>“海象”},:changed_at=>2014-05-13 15:33:58-0700}]
您的迭代将非常简单:
<>但是,如果你没有机会,你正在使用Rails >3.0.0考虑下面的方法:
使用
从审核中检索用户
<%= @contract.contract_information.audits.last.user.username %>
当Im正确读取文档时,它会返回一个包含散列的数组,这应该很容易处理。我不确定这种逻辑是否属于你的观点。
<% @contract.contract_information.history_from_audits_for([:contract_stage, :action_requested, :reason_for_contract_request, :deadline_date, :commencement_date, :existing_or_returning, :background_check_status, :priority]).each do |audit| %>
<% audit.except(:changed_at).each do |attribute, value| %>
<tr>
<td><%= audit[:changed_at].strftime("%m/%d/%Y") %></td>
<td>
<% value.each do |val| %>
<%= val %>
<% end %>
</td>
<td><%= @contract.contract_information.audits.last.user.username %></td>
</tr>
<% end %>
<% end %>
<%= @contract.contract_information.audits.last.user.username %>