0

以前私が使用した:

data: {autocomplete_source: categories_path} %>

カテゴリコントローラーのアクションインデックスを指すには.すべてうまくいきました!

カテゴリコントローラーで新しいアクションを作成しました

def search
@categories = Category.order(:name).where("name like ?", "%#{params[:term]}%")

render json: @categories.map(&:name)
end

そして、その行動を指摘しようとしました:

data: {autocomplete_source: search_categories_path} %>

しかし、私はエラーが発生します:

undefined local variable or method `search_categories_path' for #<#<Class:0x51844c8>:0x5375820>

私は何を間違えたのですか?ありがとう!

私のルート:

     products GET    /products(.:format)            products#index
          POST   /products(.:format)            products#create
 new_product GET    /products/new(.:format)        products#new
edit_product GET    /products/:id/edit(.:format)   products#edit
  product GET    /products/:id(.:format)        products#show
          PUT    /products/:id(.:format)        products#update
          DELETE /products/:id(.:format)        products#destroy
 categories GET    /categories(.:format)          categories#index
          POST   /categories(.:format)          categories#create
new_category GET    /categories/new(.:format)      categories#new
edit_category GET    /categories/:id/edit(.:format) categories#edit
 category GET    /categories/:id(.:format)      categories#show
          PUT    /categories/:id(.:format)      categories#update
          DELETE /categories/:id(.:format)      categories#destroy

ルート:

Autorails::Application.routes.draw do
resources :products


resources :categories do
 collection do
    :search
 end
end
4

3 に答える 3

3

rake routesそのルートがその名前で本当に存在するかどうかを確認してください。詳細については、 http: //guides.rubyonrails.org/routing.html#path-and-url-helpersを参照してください。

于 2013-07-30T13:58:12.200 に答える
2

に次のようなものが必要ですroutes.rb

resources :categories do
  collection do
    get :search
  end
end
于 2013-07-30T13:56:21.623 に答える
0

あなたはこのようなことをすべきです

resources :categories do
  collection do
    get :search
  end
end
于 2013-07-30T14:11:11.153 に答える