简体   繁体   English

在Ruby on Rails中传递.each循环参考对象

[英]Pass .each loop reference object in Ruby on Rails

I am writing a code in ruby on rails where I am creating dynamic rows in table which involves a .each loop. 我正在用ruby在rails上编写代码,在其中在涉及.each循环的表中创建动态行。 I want to pass the .each loop reference object but it gives me an error. 我想传递.each循环引用对象,但这给我一个错误。

Following is the code: 以下是代码:

<% pworkflows.workflow_executions_list.each do |wf| %>
  <tr>
    <td><%= wf.execution_status %></td>
    <td>
      <% if(wf.start_timestamp != nil) %>
        <%= wf.start_timestamp.localtime; %> UTC
      <% end %>
    </td>
    <td><%= wf.close_status %></td>
    <td><%= wf.execution.run_id %></td>
    <td><%= button_to "Details",{ :controller => "pages", :action => "mainpage",:rulesetinstance=>rInsId, :ndetails=>wf} %></td>
  </tr>
<% end %>

:ndetails=>wf gives an error. :ndetails=>wf给出错误。 wf is not being recognized as a correct syntax to send. 无法将wf识别为要发送的正确语法。 Please suggest a way. 请提出一种方法。

the error being: 错误是:

undefined local variable or method `id' for #<ComRuleManagement::WorkflowExecutionObject:0x00003da1751528>

When you do this 当你这样做

<%= button_to "Details",{ :controller => "pages", :action => "mainpage",:rulesetinstance=>rInsId, :ndetails=>wf} %>

you are building an html tag. 您正在建立html标记。 (since button_to is an html helper). (因为button_to是html帮助器)。 The extra options you pass through, in this instance ":rulesetinstance" and ":ndetails" will be used to make extra attributes in the element, like rulesetinstance="123" . 您通过的额外选项(在这种情况下为“:rulesetinstance”和“:ndetails”)将用于在元素中添加额外的属性,例如rulesetinstance="123" However, if you pass the wf object through, then rails will call to_s on it, and you'll end up with something that looks like this ndetails="#<Wf:0x7f518dfc6e68>" . 但是,如果将wf对象传递通过,则rails会在其上调用to_s,并且最终将得到类似于ndetails="#<Wf:0x7f518dfc6e68>" This is almost certainly not what you want in your html element. 几乎可以肯定这不是您想要的html元素。 Should you be calling another method of the wf object instead? 您应该改为调用wf对象的另一种方法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM