I'm trying to integrate tokeninput in my little rails app following Ryan Bates Railscast nbr 258.

Therefore,

I added the tokeninput files in the vendors directory

I then changes my application.js file:

//
//= require jquery
//= require jquery_ujs
//= require jquery.tokeninput
//= require bootstrap
//= require chosen-jquery
//= require jquery_nested_form
//= require bootstrap-datetimepicker.min
//= require_tree .

Then I added this code in the file categories.js.coffee

jQuery ->
  $('#company_category_list').tokenInput('/categories.json',
    theme: 'facebook'
    prePopulate: $('#company_category_list').data('load')
  )

When I go to my form, the browser console says:

TypeError: $(...).tokenInput is not a function
[Break On This Error]   

prePopulate: $('#company_category_list').data('load')

I've been looking for a couple of hours but I don't find the cause of this error. The jquery.tokeninput files seems to be loaded correctly by the asset pipeline.

Any help, suggestion welcome!

有帮助吗?

解决方案

To summarize:

The issue I had was due to the fact that I once precompiled my assets and then decided to compile on the fly:

  • It's not handy for debugging in dev mode
  • Heroku manages precompilation automatically when pushing the code

The precompilation created minified version of the assets in my public folder.

When I run my website, all the javascript files were then loaded twice: Once from the public folder and once from the normal flow.

I just deleted what I had in my public folder and it solved my issue.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top