1

I have a rails application and I want to add the jQuery datepicker, to show when the user selects a field in a form.

The field is built using the following code:

<%= f.text_field :collection_date_time %>

Resulting in:

<input class="input-medium" id="pick_collection_date_time" name="pick[collection_date_time]" size="30" type="text" />

I have added the following to my pick.js.coffee file, but when I select the field, nothing happens.

$ -> $("#pick_collection_date_time").datepicker()

For info, I'm also using the twitter bootstrap framework (and the associated js).

Any ideas why this isn't working?

1 Answer 1

1

First thing to do in this case is open firbug or chrome inspector and check if he can find the file. Next check development.log if you see any problems with assets. Maybe you did a simple typo somewhere :)

Probably you need to go to app/assets/javascripts/application.js and check if you have something like "//= require_tree ." if not add require for this file or you will have to go to config/environments/<env>.rb and add it to line config.assets.precompile += %w( <name>.js ) so he will precompile with rest.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Jakub, I've just checked with a js debugger and am getting: TypeError: 'undefined' is not a function. Any ideas?
maybe you need lack jquery or some other dependency of datapicker. I'm like 99% sure its dependency problem.

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.