我在 index.html.haml 中显示我所有的饮料时遇到问题。在观看了 Ryan Bates 之后,我最近开始使用 Thinking sphinx 进行搜索(thinking sphinx railscast。作为转向 sphinx 的一部分,我改为@drinks = Drink.all
现在@drinks = Drink.search(params[:search])
它没有在我的索引页面上显示饮料名称
饮料模型
class Drink < ActiveRecord::Base
attr_accessible :name, :detail, :recipe_steps_attributes
has_many :recipe_steps, :dependent => :destroy
has_many :ingredients, through: :recipe_steps
has_one :glass
validates_uniqueness_of :name, case_sensitive: false
accepts_nested_attributes_for :recipe_steps, :reject_if => lambda { |a| a[:amount].blank? }, :allow_destroy => true
define_index do
indexes :name
indexes ingredients.name as: :ingredient_name
end
end
饮料控制器索引
def index
@drinks = Drink.search(params[:search])
if current_user
@cabinet = Cabinet.find(current_user.id)
end
end
饮料指数.haml
= form_tag drinks_path, method: :get do
.field
= text_field_tag :search, params[:search]
= submit_tag "Search", name: nil
- @drinks.each do |drink|
= drink.name