【发布时间】:2016-10-07 23:49:23
【问题描述】:
我正在构建一个应用程序,因此我需要 jQuery 自动完成功能。为了理解这是如何工作的(几个月前才开始编码),我创建了一个基本的文章/博客应用程序。
我的目标是为我的文章标题实现一个基本搜索字段。我正在使用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
【问题讨论】:
-
在您提供的链接中有一个演示源代码的链接:github.com/bigtunacan/rails-jquery-autocomplete。复制它。
标签: jquery ruby-on-rails ruby autocomplete