我想實現我的索引視圖一個簡單的搜索框,但它給了我這個錯誤:軌搜索表單「沒有這樣的列:名稱」錯誤
SQLite3::SQLException: no such column: name: SELECT "tickets".* FROM "tickets" WHERE (name LIKE '%s%')
我想不通爲什麼是,我該如何糾正它。下面是我的MVC
查看
<h1>Listing tickets</h1>
<%= form_tag tickets_path, :method => 'get' do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag 'Search' %>
</p>
<% end %>
<table>
<tr>
...
</tr>
<% @tickets.each do |ticket| %>
<tr>
<td><%= ticket.caller_name %></td>
<td><%= ticket.called_date %></td>
<td><%= ticket.problem %></td>
...
<% end %>
</table>
型號
class Ticket < ActiveRecord::Base
attr_accessible :called_date, :caller_name, :problem
has_many :logs, :dependent=>:destroy
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
end
控制器
class TicketsController < ApplicationController
def index
@tickets = Ticket.all
@tickets = Ticket.search(params[:search])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @tickets }
end
end
好像你的票模型沒有一個'name'屬性,爲確保您的數據庫沒有一個'上name'列'票'桌。你是否執行了正確的遷移?你有沒有試過你的代碼中的某處:'ticket.name'? – MrYoshiji 2013-03-26 18:51:36