-
Notifications
You must be signed in to change notification settings - Fork 7
07.0.0 Use Server Side Validation
Patrick Baselier edited this page Oct 12, 2015
·
2 revisions
- Add Server Side Validation
See the installation instructions. Use tag 7.0.0.
- Open
backend/app/models/product.rb
and maketitle
a required attribute:
class Product < ActiveRecord::Base
validates :title, presence: true
end
- Open the app, edit a product, leave the title empty and save it.
- Inspect the error shown in the Console tab in the browser. There's an error telling that the backend did not save the record. Let's use this error and show it to the user.
- Open
frontend/app/templates/products/show.hbs
and update the markup for the title field in the form:
<div class='form-group {{if model.errors.title 'has-error'}}'>
{{input value=model.title class='form-control' placeholder='Enter a title'}}
{{#each model.errors.title as |error|}}
<div class='control-label'>{{error.message}}</div>
{{/each}}
</div>