简体   繁体   中英

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. I want to pass the .each loop reference object but it gives me an error.

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. wf is not being recognized as a correct syntax to send. 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. (since button_to is an html helper). 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" . 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>" . This is almost certainly not what you want in your html element. Should you be calling another method of the wf object instead?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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