I have a multi-model form submission that appends all model errors into a single hash called @errors. When submitting using a normal HTML post the errors correctly render in my view:
new.html.erb
<div id="error_explanation">
<% if @errors && @errors.any? %>
<% @errors.full_messages.each do |msg| %>
<h3><%= msg %></h3>
<% end %>
<% end %>
</div>
However when submitting using AJAX nothing renders, I can verify that the hash contains values when outputting to the log.
create.js.erb
<% if @errors && @errors.any? %>
<% @errors.full_messages.each do |msg| %><%= logger.info msg %><% end %> // Works!!
$('#error_explanation').html('<% @errors.full_messages.each do |msg| %><%= msg %><% end %>'); // Doesn't Work
<% end %>
You should escape the text:
If there is still a bug, provide the resulting js.