<% if resource.errors.any? %> $("#dated_cost_<%= resource.id %>").html("<%= escape_javascript(render('form')) %>"); <% else %> $("#dated_cost_<%= resource.id %>").replaceWith("<%= escape_javascript(render(resource)) %>"); <% end %>