0

index.html.haml ですべての飲み物を表示する際に問題が発生しています。私は最近、Ryan Bates を見た後、検索にThinking 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

index.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
4

1 に答える 1