我在這個railscast http://railscasts.com/episodes/37-simple-search-form?autoplay=true之後爲我的Procedure表建立了一個搜索機制。我幾乎跟着它究竟但是當我提交搜索我得到這個錯誤:簡單搜索不能在rails中工作?
ActiveRecord::RecordNotFound at /procedures
Couldn't find all Procedures with 'id': (all, {:conditions=>["name LIKE ?", "%Emergency%"]}) (found 0 results, but was looking for 2)
我想按名稱搜索程序,而這個錯誤會使得它看起來就像是由ID搜索?
這裏是視圖:
<%= form_tag procedures_path, :method => 'get' do %>
<p>
<%= text_field_tag :search, params[:search], :id => "welcome-search" %>
<%= submit_tag "Search Procedures", :name => nil, :class => "btn btn-success btn-lg" %>
我的控制器:
def index
@procedures = Procedure.search(params[:search])
render `procedures/index`
end
我的模型:
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
else
find(:all)
end
end
我很困惑,因爲railscast使得它看起來那麼容易得到工作..謝謝。
你使用的是什麼導軌版本? – panmari
我正在使用rails 4 – hey