In my rails app, I am using calendar helper
cell.innerHTML = '<%= calendar_for('start_date')%>';
The html generated by the tag is giving syntax error.
cell.innerHTML = '<img alt="Calendar"
class="calendar-trigger"
id="start_date_trigger"
src="/application/images/calendar.png?13282" />
<script type="text/javascript">
Calendar.setup({inputField : 'start_date',
ifFormat : '%Y-%m-%d',
button :'start_date_trigger' });
</script>';
What can be the quick solution for such problems?
How can I escape quotes using Rails?
kommradHomer
4,2275 gold badges55 silver badges72 bronze badges
asked Apr 5, 2012 at 7:17
hitesh israni
1,7524 gold badges26 silver badges49 bronze badges
-
Could you post the exact error please?Christoph– Christoph2012年04月05日 07:43:25 +00:00Commented Apr 5, 2012 at 7:43
-
Possible duplicate of this question: stackoverflow.com/questions/2171182/…Christoph– Christoph2012年04月05日 07:46:15 +00:00Commented Apr 5, 2012 at 7:46
-
I am getting 'Uncaught SyntaxError: Unexpected token ILLEGAL' near closing of <img/> taghitesh israni– hitesh israni2012年04月05日 07:49:43 +00:00Commented Apr 5, 2012 at 7:49
1 Answer 1
You can use the escape_javascript helper
cell.innerHTML = '<%= escape_javascript(calendar_for('start_date')) %>';
answered Apr 5, 2012 at 7:46
shingara
47k12 gold badges102 silver badges106 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Hardik Patel
@mashit: you can use alias of
escape_javascript like cell.innerHTML = '<%= j calendar_for('start_date')%>';hitesh israni
thnx, shingara and @Hardik. this was useful. also can any one of you help me with these questions.stackoverflow.com/questions/9289486/… stackoverflow.com/questions/10017651/… It would be appreciated if you can provide some directions.
lang-js