2016-06-07 175 views
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 
+0

有到源代码的链接在你提供的链接演示:https://github.com/bigtunacan/rails-jquery-autocomplete。复制它。 – 7stud

回答

1

我想你可以使用jQuery UI,因为这种功能与JS bettre。这个视频有大约1年的希望为你工作。

Tutorial

有时使用的宝石是不是最好的解决方案。

问候