Using jquery-ui-rails datepicker in an Ruby on Rails website. datepicker method not defined -
i got problem writing website ruby on rails.
bundle show * jquery-ui-rails (4.0.1)
in app/assets/javascripts/application.js
//= require jquery.ui.datepicker
in app/assets/stylesheets/application.css
*= require jquery.ui.datepicker
in app/views/layouts/application.html.erb
<%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %>
and in somepage.html.erb, got
<script type="text/javascript"> $(function(){ $("#startdate").datepicker(); $("#enddate").datepicker(); }); </script>
when running it, chrome says
uncaught typeerror: object [object object] has no method 'datepicker'
i suppose resource not being referred cause because problem fixed adding follows app/views/layouts/application.html.erb
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" /> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script> <link rel="stylesheet" href="/resources/demos/style.css" />
these found @ http://jqueryui.com/datepicker/. saw demos having working datepickers without these codes. not understand why not working in mine. got suggestions? add other mentioned above?
it because of either of following:
1) including multiple javascript files in application.html.erb
leading havoc when put altogether.
2) using other javascript file using $
jquery using. having 2 same symbols possible cause of getting no method 'datepicker'
jquery.
the alternative replace occurences of $
jquery
or
just wrap jquery code insode block following:
jquery(function($){ //all jquery code uses $ should here. });
Comments
Post a Comment