0

以下是从 ROR 中的数据库检索数据时出现错误的代码。

<div class="container">
  <div class="row">
    <div class="span9">
      <h2> List of Organization Details</h2>

      <%= b_search_bar(um_org_data_path).html_safe %>
      </br></br>


      <%= form_tag destroy_multiple_users_path, method: :delete,  data: { confirm: 'Are you sure you want to delete all these?' } do %>
        <table class="table table-hover table-condensed">
          <tr>
            <th></th>
            <th>Organization Name</th>
            <th>Organization Description</th>
            <th>Office Address</th>
            <th>Office Phone Number</th>
            <th>Actions</th>
          </tr>


         <% @um_org_data.each do |um_org_data| %>
            <tr>
              <td><%= check_box_tag "deleted_ids[]", um_org_data.org_name%></td>
              <td><%= um_org_data.org_desc%></tdc>
              <td><%= um_org_data.offc_addr%></td>
              <td><%= um_org_data.offc_ph%></td>
              <td>
                <%= link_to "<i class='icon-eye-open'></i>".html_safe, "data-original-title" => "View Details", "data-placement" => "bottom", :rel => "nofollow", :class => 'bg-color-none' %>
              </td>
          </tr>

        </tr>
        </table>
        <%end%>


    </div>
  </div>
</div>

<!--/////////////////////////////////////////////////////////////////////////////--><h1>Listing Organization Data</h1>

<table>
  <tr>
    <th>Organization Name</th>
    <th>Organization Description</th>
    <th>Office Address</th>
    <th>Office Phone Number</th>
    <th>Actions</th>
    <th></th>
    <th></th>
  </tr>

<% @um_org_data.each do |um_org_datum| %>
  <tr>
    <td><%= um_org_datum.org_name %></td>
    <td><%= um_org_datum.org_description %></td>
    <td><%= um_org_datum.offc_addr %></td>
    <td><%= um_org_datum.offc_ph %></td>
    <td><%= link_to 'Show', um_org_datum %></td>
    <td><%= link_to 'Edit', edit_um_org_datum_path(um_org_datum) %></td>

  </tr>
<% end %>
</table>

<br />

<%= link_to 'New Um org datum', new_um_org_datum_path %>

以上是两种类型的代码片段以上是我想要做的实际事情,但出现以下错误:

NoMethodError in Um_org_data#index

Showing /home/wasif/RoshanERP/app/views/um_org_data/index.html.erb where line #25 raised:

undefined method `org_desc' for #<UmOrgDatum:0x007fc0e8b17000>

Extracted source (around line #25):

22:          <% @um_org_data.each do |um_org_data| %>
23:             <tr>
24:               <td><%= check_box_tag "deleted_ids[]", um_org_data.org_name%></td>
25:               <td><%= um_org_data.org_desc%></tdc>
26:               <td><%= um_org_data.offc_addr%></td>
27:               <td><%= um_org_data.offc_ph%></td>
28:               <td>

下面的代码在哪里可以正常工作。!提前致谢!

4

1 回答 1

0

代替

<%= um_org_data.org_desc %>

你应该有

<%= um_org_data.org_description %>

因为这是您在 DB 中的列名,所以 activerecord 会自动创建UmOrgDatum#org_description方法来获取该列的值。它不会创建方法UmOrgDatum#org_desc,因为您的表中没有这样的列,这就是您收到错误的原因。

于 2013-08-13T10:38:13.490 回答