Sometimes javascript works perfect, and sometimes not in ruby โ€‹โ€‹on rails 4

I used the datepicker in a calendar that shows perfectly, but does not show an arrow button to change the month. and also sometimes give an error:

ActionController::RoutingError (No route matches [GET] "/assets/images/ui-icons_ef8c08_256x240.png")

Datepicker issue

datepicker.js

$(document).ready(function(){
  $('[data-behaviour~=datepicker]').datepicker();
});

CSS link

Sorry for the too long question and tell me if I miss something.

Thank you very much in advance

Edit: I noticed that when I delete the public / assets directory and then enter rake assets: this time the precompilation does not display an error, but the arrow still does not appear.

+4
source share
3 answers

, turbolinks, 4 . turbolinks $(). . railscast

data: { no_turbolink: true }

gemfile, . , ui-icons_ef8c08_256x240.png

/assets/images/
+1

. javascript, : load.

Meltemi

ready = ->

  ...your coffeescript goes here...

$(document).ready(ready)
$(document).on('page:load', ready)

JavaScript:

var ready;
ready = function() {

  ...your javascript goes here...

};

$(document).ready(ready);
$(document).on('page:load', ready);

Rails 4: $(document).ready() -

+1

Install jquery-turbolinksgem first . And then, remember to move your included Javascript files from the end of your body application.html.erbto it <head>.

As described here , if you put the javascript link of the application in the footer to optimize the speed, you will need to move it to load it to the content in the tag. This solution worked for me.

+1
source

Source: https://habr.com/ru/post/1537777/


All Articles