0

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

/ doesn't change anything but the idea about new line, I put it all in one line and now it's ok, thanks
You're welcome. I think you need the backslash \ instead of the forward slash /.

Your Answer

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.