从数据库mysql检索数据时出错

时间:2013-08-13 10:32:53

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2

以下是在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>

以下代码的评论在哪里工作正常。提前谢谢!

1 个答案:

答案 0 :(得分:0)

而不是

<%= um_org_data.org_desc %>
你应该

<%= um_org_data.org_description %>

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