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.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.
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/
You can also follow the instruction here. Basically you have to tell javascript to also execute on page:load.
Credit to Meltemi
Coffee:
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);
First, install jquery-turbolinks
gem. And then, don't forget to move your included Javascript files from end of body of your application.html.erb
to its <head>
.
As described here, if you have put the application javascript link in the footer for speed optimization reasons, you will need to move it into the tag so that it loads before the content in the tag. This solution worked for me.
来源:https://stackoverflow.com/questions/23254379/sometimes-javascript-run-perfect-and-sometimes-not-in-ruby-on-rails-4