Question

I followed the episode 111 on Railscast.

http://railscasts.com/episodes/111-advanced-search-form-revised?view=asciicast

I modifed the model names but the other stuff is basically the same. I only want to show you the code where my error appears: Controller:

   def suche
     @search = Search.find(params[:id])
   end

Model:

  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

And my view:

<%= @search.patients.each do |f| %>
  <%= f %>
<% end %>

Somehow i get this error:

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| %> 

PATient model:

 class Patient < ActiveRecord::Base
    attr_accessible :drucken, :extraanrede, :extratext, :geburtsdatum, :geschlecht,:nachname, :vorname
 scope :drucken, where(:drucken => true)
 end
Was it helpful?

Solution

Class name in rails are singular, so you want

Patient.order(:vorname)

in your find_patients method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top