我在 Railscast 上关注了第 111 集。
http://railscasts.com/episodes/111-advanced-search-form-revised?view=asciicast
我修改了型号名称,但其他内容基本相同。我只想向您显示我的错误出现的代码: 控制器:
def suche
@search = Search.find(params[:id])
end
模型:
class Search < ActiveRecord::Base
attr_accessible :ausdruck, :keyword, :maximum, :minimum, :rund, :zeitraum
def patients
@patients ||= find_patients
end
private
def find_patients
patients = Patients.order(:vorname)
patients = patients.where("vorname like ?", "%#{keyword}%") if keyword.present?
patients
end
end
我的观点:
<%= @search.patients.each do |f| %>
<%= f %>
<% end %>
不知何故,我得到了这个错误:
NameError in Patients#suche
Showing C:/geburtstag/app/app/views/patients/suche.html.erb where line #1 raised:
uninitialized constant Search::Patients
Extracted source (around line #1):
1: <%= @search.patients.each do |f| %>
患者型号:
class Patient < ActiveRecord::Base
attr_accessible :drucken, :extraanrede, :extratext, :geburtsdatum, :geschlecht,:nachname, :vorname
scope :drucken, where(:drucken => true)
end