【问题标题】:rails-jquery-autocomplete and acts_as_taggable form routingrails-jquery-autocomplete 和acts_as_taggable 表单路由
【发布时间】:2016-07-08 16:49:32
【问题描述】:

Acts_as_taggable 工作正常。我执行以下操作将rails-jquery-autocomplete 添加到我的网络应用程序中。我在生产中使用 Rails 4.2.2/Heroku。

add gem 'rails-jquery-autocomplete' to gem file
bundle install
heroku run bundle install

updated my application.js file to 

//= require jquery
//= require jquery_ujs
//= require jquery-ui/autocomplete
//= require autocomplete-rails
//= require bootstrap
//= require turbolinks
//= require_tree .

and pushed to Heroku

// Model
class Photo < ActiveRecord::Base
  acts_as_taggable_on :tags
end

// Controller
class PhotosController < ApplicationController
  autocomplete :tag, :name, :class_name => 'ActsAsTaggableOn::Tag'
  ...
private
  def photo_params
    params.require(:photo).permit(:picture, :title, :tag_list)
  end
end

// Routes
get 'tags/:tag', to: 'photos#index', as: :tag
resources :photos do
    get :autocomplete_tag_name, :on => :collection
end

//View  

<% form_for :photo, url: photos_path, html: {multipart: true } do |form| %>
  <%= f.file_field :picture %>
  <%= f.text_field :title %> 
  <%= form.label :tag_list, "Tags" %>
  <%= form.autocomplete_field :tag_list, autocomplete_tag_name_photos_path, :"data-delimiter" => ', ' %>
<% end %>

表单已保存,标签和照片已添加到数据库中,但自动完成功能根本不起作用。

我经历过thesetopics,但他们没有帮我找到答案。

【问题讨论】:

  • 感谢您的精彩帖子。我已经成功显示了自动完成标签,但是当我点击提交按钮时出现问题,对于创建新的或编辑,它什么也没做。并且按钮似乎更改为禁用样式。在日志中,仅显示 GET 自动完成的最后状态。

标签: ruby-on-rails autocomplete


【解决方案1】:

我忘记添加 gem 'jquery-ui-rails'。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    相关资源
    最近更新 更多