Maki
Maki

Reputation: 913

rails 3 js code error

I have this code in my process_form.js.erb file:

$('#write_offs_table > tbody').append('<tr class="list-line-<%= cycle('even', 'odd') %>" id="<%= @write_off.id %>">                                           
                                           <td class="name"><%= @write_off.date %></td>
                                           <td><%= @write_off.user.name %></td>
                                           <td><%= @write_off.status %></td>
                                           </tr>');

it doesn't execute and chrome shows me an error:

Uncaught SyntaxError: Unexpected token ILLEGAL

Upvotes: 0

Views: 165

Answers (1)

Artem Kalinchuk
Artem Kalinchuk

Reputation: 6652

Try this:

$('#write_offs_table > tbody').append('<tr class=list-line-<%= cycle("even", "odd") %> id="<%= @write_off.id %>">\                                     
                                       <td class="name"><%= @write_off.date %></td>\
                                       <td><%= @write_off.user.name %></td>\
                                       <td><%= @write_off.status %></td>\
                                       </tr>');

I used the \ character to tell javascript that it continues on a new line.

Upvotes: 1

Related Questions