Reputation: 7136
I am building a web app using Ruby on Rails. I would like to add some Javascript to a CoffeeScript file
var month = <%= @pin.duedate.month %>;
var day = <%= @pin.duedate.day %>;
var date = new Date(year, month, day);
$("#due_date_timer").countdown({until: date});
At the moment my CoffeeScript file (pins.js.coffee
) includes this:
$ ->
$('#pins').imagesLoaded ->
$('#pins').masonry
itemSelector: '.box'
isFitWidth: true
What is the proper way to include the Javascript into a CoffeeScript file?
Update
Followed Amadan's direction
In pins.js.coffee
$ ->
$('#pins').imagesLoaded ->
$('#pins').masonry
itemSelector: '.box'
isFitWidth: true
year = <%= @pin.duedate.year %>
month = <%= @pin.duedate.month %>
day = <%= @pin.duedate.day %>
date = new Date(year, month, day)
$("#due_date_timer").countdown({until: date})
I get an error
ExecJS::ProgramError
unexpected =
year = <%= @pin.duedate.year %>
Upvotes: 0
Views: 323
Reputation: 198436
The CoffeeScript equivalent of your code is exactly the same, but without var
and ;
.
Upvotes: 2
Reputation: 253
You can embed vanilla javascript in your coffeescript by using backticks.
http://coffeescript.org/#embedded
Upvotes: 1
Reputation:
If you have existing javascript code can try following ...
which will convert javascript code to coffee script.
Upvotes: 1