我正在搜索我的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行是:
问题是什么,我该如何解决?
答案 0 :(得分:0)
好的,在conf.rb
中搜索updated_at LIKE ?'
代替updated_at LIKE ? OR'
这是一个语法错误。关于问题,我将sort_column
中的confs_controller.rb
从...params[:sort] : "name"
更改为...params[:sort] : "machine_name"