diff options
author | Oscar Del Ben <info@oscardelben.com> | 2012-04-21 12:17:51 +0200 |
---|---|---|
committer | Oscar Del Ben <info@oscardelben.com> | 2012-04-21 12:17:51 +0200 |
commit | 3da2b530aff28d4ea0272e36578188bb6869cbcc (patch) | |
tree | 61923eb8c4d725c38e314e706740362a66c01021 /guides/code/getting_started | |
parent | 504ba12e8cd256b08a43f8ee56c6e2b0272ce6cc (diff) | |
download | rails-3da2b530aff28d4ea0272e36578188bb6869cbcc.tar.gz rails-3da2b530aff28d4ea0272e36578188bb6869cbcc.tar.bz2 rails-3da2b530aff28d4ea0272e36578188bb6869cbcc.zip |
Add validation code to getting started guide and improve validation
section
Diffstat (limited to 'guides/code/getting_started')
-rw-r--r-- | guides/code/getting_started/app/controllers/posts_controller.rb | 1 | ||||
-rw-r--r-- | guides/code/getting_started/app/views/posts/_form.html.erb | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb index 2ad69a9bcf..947cd2a767 100644 --- a/guides/code/getting_started/app/controllers/posts_controller.rb +++ b/guides/code/getting_started/app/controllers/posts_controller.rb @@ -9,6 +9,7 @@ class PostsController < ApplicationController end def new + @post = Post.new end def create diff --git a/guides/code/getting_started/app/views/posts/_form.html.erb b/guides/code/getting_started/app/views/posts/_form.html.erb index 51fa3f4f12..18cb29f335 100644 --- a/guides/code/getting_started/app/views/posts/_form.html.erb +++ b/guides/code/getting_started/app/views/posts/_form.html.erb @@ -1,4 +1,14 @@ <%= form_for :post, :url => { :action => :create } do |f| %> + <% if @post.errors.any? %> + <div id="errorExplanation"> + <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> + <ul> + <% @post.errors.full_messages.each do |msg| %> + <li><%= msg %></li> + <% end %> + </ul> + </div> + <% end %> <p> <%= f.label :title %><br> <%= f.text_field :title %> |