From 5be9480128b2841647b204ba19ec9f45dac438f5 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 7 Jul 2018 17:20:08 -0400 Subject: Added tag autocompletion refs #2 --- app/assets/javascripts/admin/records.coffee | 3 +++ app/assets/javascripts/application.js | 2 ++ app/assets/stylesheets/admin.css.scss | 1 + app/controllers/tags_controller.rb | 11 +++++++++++ 4 files changed, 17 insertions(+) create mode 100644 app/controllers/tags_controller.rb (limited to 'app') diff --git a/app/assets/javascripts/admin/records.coffee b/app/assets/javascripts/admin/records.coffee index 7a11ce1..27cdb78 100644 --- a/app/assets/javascripts/admin/records.coffee +++ b/app/assets/javascripts/admin/records.coffee @@ -25,3 +25,6 @@ $(document).on "turbolinks:load", -> published_field_toggle($(this).prop("checked")) $("input[type=tags]").each -> tagsInput(this) + $(".tags-input input[type=text]").autocomplete({ + source: Routes.suggest_tags_path() + }) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a81b3b2..58e8fb7 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,4 +15,6 @@ //= require turbolinks //= require ckeditor/init //= require tags-input +//= require jquery-ui +//= require js-routes //= require_tree ./admin diff --git a/app/assets/stylesheets/admin.css.scss b/app/assets/stylesheets/admin.css.scss index 95d1ed0..cb6fb96 100644 --- a/app/assets/stylesheets/admin.css.scss +++ b/app/assets/stylesheets/admin.css.scss @@ -1,5 +1,6 @@ /* *= require normalize-rails *= require tags-input + *= require jquery-ui *= require_tree ./admin */ diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb new file mode 100644 index 0000000..7115d28 --- /dev/null +++ b/app/controllers/tags_controller.rb @@ -0,0 +1,11 @@ +class TagsController < ApplicationController + + def suggest + @tags = ActsAsTaggableOn::Tag.pluck(:name).select do |tag| + tag.starts_with? params[:term] + end + + render json: @tags + end + +end -- cgit 1.4.1