我正在关注 railscast 111 进行高级搜索。我得到一个未定义的局部变量或方法“find_users”。我一行一行地跟着它。不知道如何解决这个问题,因为我在搜索后得到了错误。它指向 Searches#show 中的 NoMethodError。任何帮助,将不胜感激。
显示.html:
搜索控制器:
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
搜索.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