[Rails] Record when the event did not fire when the javascript file name is the same as the controller

javascript event does not fire.

app/assets/javascripts/users.js



$(function(){
  $("#user-search-field").on("keyup", function() {
    console.log("OK");
  });
});

I changed the file name of js.

app/assets/javascripts/test.js



$(function(){
  $("#user-search-field").on("keyup", function() {
    console.log("OK");
  });
});

The event ignited.

I tried different file names.

○ test.js ○ ttt.js ○ user.js × users.js × groups.js ○ group.js

Only the same file name as the controller is useless.

When I looked closely, I noticed that there was the following file.

app/assets/javascripts/... groups.coffee users.coffee

Suspecting the influence of coffeescript, deleting the coffee file now fires an event.

Error when restarting rails again.

LoadError: cannot load such file -- coffee_script 

uninstall coffee-rails

Gemfile


# gem 'coffee-rails', '~> 4.2'

terminal


bundle install

terminal


rails tmp:cache:clear

Solution!

reference

https://qiita.com/yakimeron/items/7945a1350bd4b8c2438b

Recommended Posts

[Rails] Record when the event did not fire when the javascript file name is the same as the controller
[Rails] When the layout change of devise is not reflected
Solved the problem that the scroll event did not fire in JQuery
When the bean class name is duplicated
[Rails] Annotate is not executed when migrating
When the project is not displayed in eclipse
[Railways] Railways does not work when the RubyMine project root is other than the Rails root directory.
[Ruby on rails] When executing the heroku command, bash: heroku: command not found is displayed. [Rails tutorial]