簡體   English   中英

rails 3 ActiveRecord :: StatementInvalid

[英]rails 3 ActiveRecord::StatementInvalid

我正在搜索我的index.html.erb,它給我一個錯誤。 這是我的index.html.erb:

<% provide(:title, 'All configurations') %>
<h1>All configurations</h1>

<%= form_tag conf_show_all_path, :method => 'get' do %>
  <%= hidden_field_tag :direction, params[:direction] %>
  <%= hidden_field_tag :sort, params[:sort] %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>
  </p>
<% end %>

<table class="pretty" border="1" cellpadding="10">  
  <tr>
    <th><%= sortable("machine_name",       "M.Name")       %></th>
    <th><%= sortable("machine_brand",      "M.Brand")      %></th>
    <th><%= sortable("machine_model",      "M.Model")      %></th>
    <th><%= sortable("control_unit_brand", "C.Unit Brand") %></th>
    <th><%= sortable("control_unit_model", "C.Unit Model") %></th>
    <th><%= sortable("tool_axis_x",        "Axis X")       %></th>
    <th><%= sortable("tool_axis_y",        "Axis Y")       %></th>
    <th><%= sortable("tool_axis_z",        "Axis Z")       %></th>
    <th><%= sortable("rotary_axis_number", "R.Axis")       %></th>
    <th><%= sortable("linear_axis_number", "L.Axis")       %></th>
    <th><%= sortable "description"                         %></th>
    <th><%= sortable("name",               "Developer")    %></th>
    <th><%= sortable "updated_at"                          %></th>
  </tr>  

  <% for conf in @confs %>  
  <tr class="<%= cycle('oddrow', 'evenrow') -%>">
    <td><%= link_to conf.machine_name, conf %></td>
    <td><%= conf.machine_brand %></td>
    <td><%= conf.machine_model %></td>
    <td><%= conf.control_unit_brand %></td>
    <td><%= conf.control_unit_model %></td>
    <td><%= conf.tool_axis_x %></td>
    <td><%= conf.tool_axis_y %></td>
    <td><%= conf.tool_axis_z %></td>
    <td><%= conf.rotary_axis_number %></td>
    <td><%= conf.linear_axis_number %></td>
    <td><%= conf.description %></td>
    <td><%= conf.developer.name unless conf.developer_id.blank? %></td>
    <td><%= conf.updated_at %></td>
  </tr>
  <% end %>
</table>
<%= will_paginate @confs %>

這是在conf.rb中搜索:

def self.search(search)
  if search
    q = "%#{search}%"
    where('machine_name LIKE ? OR 
           machine_brand LIKE ? OR 
           machine_model LIKE ? OR 
           control_unit_brand LIKE ? OR 
           control_unit_model LIKE ? OR 
           tool_axis_x LIKE ? OR 
           tool_axis_y LIKE ? OR 
           tool_axis_z LIKE ? OR 
           rotary_axis_number LIKE ? OR 
           linear_axis_number LIKE ? OR 
           description LIKE ? OR
           developer_id LIKE ? OR
           updated_at LIKE ? OR',
          q,q,q,q,q,q,q,q,q,q,q,q,q)
  else
    scoped
  end
end

這是application_helper.rb中的可排序方法:

def sortable(column, title = nil)  
    title ||= column.titleize
    css_class = (column == sort_column) ? "current #{sort_direction}" : nil
    direction = (column == sort_column && sort_direction == "asc") ? "desc" : "asc"  
    link_to title, params.merge(:sort => column, :direction => direction, :page => nil), {:class => css_class}
end

最后,這是錯誤:

ActiveRecord::StatementInvalid in Confs#index
SQLite3::SQLException: no such column: name: SELECT  "confs".* FROM "confs"  ORDER BY name asc LIMIT 10 OFFSET 0
Extracted source (around line #30)

第30行是這樣的:

有什么問題,我該如何解決?

好的,在conf.rb搜索conf.rb應該更新為updated_at LIKE ?' 而不是updated_at LIKE ? OR' updated_at LIKE ? OR'這是一個語法錯誤。 關於問題,我將sort_column中的confs_controller.rb...params[:sort] : "name"更改為...params[:sort] : "machine_name"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM