I am following railscast 111 for advanced search. I am getting a undefined local variable or method `find_users'. I have followed it line for line. Not sure how to fix this as I get the error after doing the search. It's pointing to NoMethodError in Searches#show. Any help would be appreciated.
show.html:
searches controller:
def new
@search = Search.new
end
def create
@search = Search.new(params[:search])
if @search.save
redirect_to @search
else
render 'new'
end
end
def show
@search = Search.find(params[:id])
@users = @search.users
end
end
search.rb:
attr_accessible :age, :children, :ethnicity, :gender, :religion, :zip_code
def users
@users ||= find_users
private
def find_users
users = User.order(:id)
users = users.where(gender: gender) if gender
users = users.where(zip_code: zip_code) if zip_code
users = users.where(children: children) if children
users = users.where(religion: religion) if religion
users = users.where(ethnicity: ethnicity) if ethnicity
users
end
end
end
In your search.rb
you must add the method find_users
, like so:
def find_users
User.find(:all, :conditions => conditions)
end
Then you must also include all the method conditions
and specify them. Please follow the railscast, it is very explicit.