我正在我的ruby on rails app上添加搜索功能。基于Ryan Bates教程#111。
出于某种原因,我的节目页面中的渲染调用导致
Name Error
uninitialized constant Search::Properties
我的控制器很简单
class SearchesController < ApplicationController
def new
@search = Search.new
end
def create
@search = Search.create(search_params)
redirect_to @search
end
def show
@search = Search.find(params[:id])
end
private
def search_params
params.require(:search).permit(:keywords, :category, :min_price, :max_price, :bedrooms, :bathrooms, :garage)
end
end
我在模型中创建了一个新类
class Search < ActiveRecord::Base
def properties
properties = Properties.all
properties = properties.order(:title)
properties = properties.where(["title LIKE ?","%#{keywords}%"]) if keywords.present?
properties = properties.where([category: category]) if category.present?
properties = properties.where(["price >= ?","%#{min_price}%"]) if min_price.present?
properties = properties.where(["price <= ?","%#{max_price}%"]) if max_price.present?
properties = properties.where(["bedrooms == ?","%#{bedrooms}%"]) if bedrooms.present?
properties = properties.where(["bathrooms == ?","%#{bathrooms}%"]) if bathrooms.present?
properties = properties.where(["garage == ?","%#{garage}%"]) if garage.present?
properties
end
end
我的观点
<div class="row property-list-wrapper">
<div class="container">
<div class="col-md-8 property-list-left">
<h1>We've found <%= pluralize(@properties.count, 'property')%> </h1>
<%= render @properties %>
</div>
<div class="col-md-4 property-list-right">
</div>
</div>
</div>
我的渲染标记似乎没有在我的模型中找到该类。我可能在控制器中遗漏了一些东西吗?
我正在使用rails 4.2.7和ruby 2.2.4p230