codebrew / backbone-rails

Easily use backbone.js with rails 3.1
MIT License
1.62k stars 255 forks source link

Views don't show errors #118

Open jscheid opened 12 years ago

jscheid commented 12 years ago

It seems that the generated new.jst.ejs and edit.jst.ejs templates don't contain code to show any server-side errors that occurred when saving/updating the model.

The generated code reads:

<div class="field">
  <label for="name"> name:</label>
  <input type="text" name="name" id="name" value="<%= name %>" >
</div>

... when it should probably read something more like:

<div class="field">
  <label for="name"> name:</label>
  <input type="text" name="name" id="name" value="<%= name %>" >
  <% if (typeof errors != "undefined" && errors['name']) { %>
    <div class="field-error"><%= errors.name %></div>
  <% } %>
</div>
westonplatter commented 10 years ago

@jscheid any ideas for how you'd like to have this implemented? I usually render errors in a _messages.html.erb partial file when I'm running with a Rails rendered stack.

Maybe one idea is catching errors from the Backbone.sync event fire, and then render whatever errors are generated from that. Would love to consider adding this to http://westonplatter.com/railsy_backbone.

Happy to work PRs through the system. :)