0
我正在構建一個應用程序,因此我需要jQuery自動完成。爲了理解這是如何工作的(剛剛在幾個月前開始編碼),我創建了一個基本的文章/博客應用程序。自動完成jquery和Rails4
我的目標是爲我的文章的標題實現一個基本的搜索字段。我正在使用rails-jquery-autocomplete。
但是,根據文檔,我可以安裝一切到目前爲止。但是現在我完全失去了如何使這個東西實際上工作(我試圖通過文檔實現它,但它沒有工作)。
我的問題是我的代碼應該如何使這項工作?
目前我的代碼看起來像:
的routes.rb
Rails.application.routes.draw do
resources :articles
end
article.rb
class Article < ActiveRecord::Base
end
articles_controller.rb
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def show
@article = Article.find params[:id]
end
def new
end
def create
@article = Article.new article_params
if @article.save
redirect_to @article
else
render 'new'
end
end
private
def article_params
params.require(:article).permit :title, :text
end
end
schema.rb
ActiveRecord::Schema.define(version: 20160607060132) do
create_table "articles", force: :cascade do |t|
t.string "title"
t.text "text"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
有到源代碼的鏈接在你提供的鏈接演示:https://github.com/bigtunacan/rails-jquery-autocomplete。複製它。 – 7stud