Search code examples
javascriptruby-on-rails-4datepickersprocketsturbolinks

sometimes javascript run perfect and sometimes not in ruby on rails 4


I used datepicker in calendar it shows perfect but not shows the arrow button to change month. and also give error sometimes like this:

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 too long question and tell me if i miss something.

Big thanks in advance

Edit: I observed that when i delete the public/assets directory and then enter rake assets:precompile this time error is not showing but arrow still is not showing.


Solution

  • It looks like turbolinks problem which are added to rails 4 by default. In turbolinks $(document).ready is not always firing. You can see more information about turbolinks and some suggestions how to use them here railscast or you can add to some links

    data: { no_turbolink: true }
    

    You can also just remove the turbolinks from gemfile if you don't need them. Also check if you have the ui-icons_ef8c08_256x240.png in

    /assets/images/