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,127
  • 5
  • 51
  • 68
hitesh israni
  • 1,742
  • 4
  • 25
  • 48

1 Answers1

2

You can use the escape_javascript helper

cell.innerHTML = '<%= escape_javascript(calendar_for('start_date')) %>';
shingara
  • 46,608
  • 11
  • 99
  • 105
  • 1
    @mashit: you can use alias of `escape_javascript` like `cell.innerHTML = '<%= j calendar_for('start_date')%>';` – Hardik Patel Apr 05 '12 at 07:55
  • thnx, shingara and @Hardik. this was useful. also can any one of you help me with these questions.http://stackoverflow.com/questions/9289486/redmine-plugin-requires-restart-after-every-code-change http://stackoverflow.com/questions/10017651/ide-for-redmine-rails-and-configuring-the-project It would be appreciated if you can provide some directions. – hitesh israni Apr 05 '12 at 09:16