【问题标题】:Autocomplete jquery and Rails4自动完成 jquery 和 Rails4
【发布时间】: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

【问题讨论】:

标签: jquery ruby-on-rails ruby autocomplete


【解决方案1】:

我认为你可以使用 Jquery UI,因为这种功能用 js 更好。这个视频有大约 1 年的时间希望对你有用。

Tutorial

有时使用 gem 并不是最好的解决方案。

问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 2010-09-23
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-08
    相关资源
    最近更新 更多