1

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
3
  • Could you post the exact error please? Commented Apr 5, 2012 at 7:43
  • Possible duplicate of this question: stackoverflow.com/questions/2171182/… Commented Apr 5, 2012 at 7:46
  • I am getting 'Uncaught SyntaxError: Unexpected token ILLEGAL' near closing of <img/> tag Commented Apr 5, 2012 at 7:49

1 Answer 1

2

You can use the escape_javascript helper

cell.innerHTML = '<%= escape_javascript(calendar_for('start_date')) %>';
answered Apr 5, 2012 at 7:46
Sign up to request clarification or add additional context in comments.

2 Comments

@mashit: you can use alias of escape_javascript like cell.innerHTML = '<%= j calendar_for('start_date')%>';
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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.