2014-03-19 38 views
0

我已經按照提及的所有內容here。但是,它不起作用。我有question_controller。我正試圖想出自動完成搜索框。我已創建finders_controller.rb與我具有以下的代碼route_to_app /應用/控制器/ finders_controller.rbRails 3.2.16自動完成

class FindersController < ApplicationController 
autocomplete :question, :question 
end 

在路線route_to_app /配置/ routes.rb中

resources :finders do 
    get :autocomplete_question_question, :on => :collection 
end 

在視圖部分route_to_app /app/views/questions/index.html.erb

<div class = "span-24 last box"> 
    <%form_for @finder do |f|%> 
<%= f.autocomplete_field :question_question, autocomplete_question_question_finders_path %> 
<%end%> 
</div><!--End span-24 box.-->` 

代碼route_to_app /應用/視圖/發現者/ index.html.erb是空白的。

的javascrip文件看起來像route_to_app /應用/資產/ Java腳本/ application.js中

//= require jquery 
//= require jquery_ujs 
//= require_tree . 
//= require autocomplete-rails 

我收到以下錯誤消息。我相信根本錯誤:

未定義的方法`MODEL_NAME」的NilClass:類 顯示C:/Sites/iHardie/app/views/questions/index.html.erb在行#8提出:

 <div class = "span-24 last box"> 
    <%form_for @finder do |f|%> 
<%= f.autocomplete_field :question_question, autocomplete_question_question_finders_path %> 
<%end%> 
</div><!--End span-24 box.--> 

有人可以幫忙嗎?我在這裏呆了一段時間。我會買一個漂亮的比薩或送一張好禮物卡給誰來幫助我解決問題。

這是問題數據庫的樣子:

create_table "questions", :force => true do |t| 
t.string "question" 
t.string "answer" 
t.integer "product" 
t.integer "priority" 
t.integer "user" 
t.string "type" 
t.boolean "favorite" 
t.datetime "created_at", :null => false 
t.datetime "updated_at", :null => false  end 
+0

我正在按問題搜索問題數據庫。謝謝。理想情況下,我想將其放置在菜單欄中。 – takaloosingh

+0

您可以添加您的問題模型的外觀副本嗎?你應該可以從你的schema.rb文件中抓取它。 – bigtunacan

回答

0

開始了與以下內容,如果您仍然有問題,我們可以從那裏。

既然你已經發布了模式文件,那麼就有一個問題馬上跳出來。你已經聲明瞭自動完成如下。

class FindersController < ApplicationController 
    autocomplete :question, :question 
end 

這應該按如下方式使用

autocomplete :table_name, :method_name 

所以表名需要符合什麼在你的數據庫/ schema.rb這並不做自動多元化。這裏你使用了:table_name => :question,但是在你的schema.rb文件中,表名是questions

試着改變這一點,讓我知道你是否有其他問題。

+0

感謝您的回覆。什麼都沒有你有沒有任何可行的代碼。我將複製並複製該代碼。謝謝。 – takaloosingh