Reputation: 6924
I want to add a datepicker to my HAML markup. I started with that question and tried 2 approaches to add an script:
%h3
Please enter the following information:
= form('/some_path', :post)
= input(:date, :start_date, class: "formbox")
= input(:date, :end_date, class: "formbox")
= submit('Submit', class: "button")
%script(type="text/javascript")
$(function() {$( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});});
and
:javascript
$(function() {
$( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});
});
This one was finally correct, problem was in form part.
Both produce an error syntax error, unexpected keyword_ensure, expecting end-of-input
on line :javascript
or %script(type="text/javascript")
How to fix that and add the script?
Upvotes: 0
Views: 83
Reputation: 121000
%script
tag expects curly brackets; in the latter example there is =content_for
tag needed:
%script{data:{'foo'=> 'bar'}, 'type'=> "text/javascript"}
= content_for :javascripts do
:javascript
$(function() {
$( "#start_date, #end_date" ).datepicker({format: 'yyyy-mm-dd'});
});
Upvotes: 1