5.11 Adding Some Validation

Rails includes methods to help you validate the data that you send to
models. Open the app/models/post.rb file and edit it:

class Post < ActiveRecord::Base
  validates :title, presence: true,
                    length: { minimum: 5 }
end

These changes will ensure that all posts have a title that is at least
five characters long. Rails can validate a variety of conditions in a
model, including the presence or uniqueness of columns, their format,
and the existence of associated objects. Validations are covered in
detail in Active Record Validations