1

I'm running rails 3 on localhost and was getting the error

Uncaught TypeError: Object [object Object] has no method 'datepicker'

after following railscasts http://railscasts.com/episodes/213-calendars, and putting both lines below into my application.html.erb file

<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "application" %>

I actually solved this error by downloading jquery-ui.min.js file and putting it in my javascripts project folder, and replacing one of the lines, to the result below :

<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css", "application" %>
    <%= javascript_include_tag "application" %>

I also do not understand why i need to put my datepicker function inside my application.js :

$(function() {

  $('#start_date').datepicker();
  $('#end_date').datepicker();
})

and cannot put it on my users.js.coffee file with just the lines :

$('#start_date').datepicker();
$('#end_date').datepicker();

Anyone can explain why adding the js file locally solved this error, and why i cannot put my datepicker into my local coffee file, or if i can, can you please tell me how?

Thank you

1
  • +1 for explaining how to fix the "has no method 'datepicker'" error. Commented Oct 16, 2012 at 22:01

1 Answer 1

1

I'm not a coffescript expert, but I think you have to do this.

jQuery ->
  ### your code here ###
Sign up to request clarification or add additional context in comments.

2 Comments

This solves my problem of putting context-specific scripts in application.js. Let us see if anyone can explain the first part of the question in two days. If not, i shall accept your answer
I would imagine that coffeescript is wondering where the variable datepicker came from. But again, I don't use coffeescript. I'd like to but it's not an option right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.