I have a rails template (.rhtml file) generating a Javascript object. It looks something like the following:
var volumes = {
<% for volume in @volumes %>
<%= volume.id %> : <%= volume.data %>
<%= ',' unless volume === @volumes.last %>
<% end %>
};
Note the unless
statement modifier to suppress printing the comma after the last element (to satisfy Internet Explorer, which incredibly doesn't support trailing commas in JSON properties declarations).
This appears to work, but as a matter of style, do people think it is reasonable to rely on <%= value unless condition %>
in the template generating an appropriate render
call?