Reputation: 1181
I am building an app and therefore I need jQuery autocomplete. To understand how this works (just started coding few months ago) I created a basic articles/blog app.
My goal is to implement a basic search field for the titles of my articles. I'm using rails-jquery-autocomplete.
However I could install everything so far according to the documentation. But now I'm totally lost on how to make this thing work actually (I tried to implement it via the documentation but it did not work).
My question is how my code should look like to make this work?
Currently my code looks like:
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
Upvotes: 0
Views: 40
Reputation: 52
I think you can use Jquery UI, because this kind of functionality is bettre with js. This video has around 1 year hope works for you.
Sometimes use a gem is not the best solution.
Regards
Upvotes: 1