aboutsummaryrefslogtreecommitdiffstats
path: root/guides/code
diff options
context:
space:
mode:
authorOscar Del Ben <info@oscardelben.com>2012-04-21 12:17:51 +0200
committerOscar Del Ben <info@oscardelben.com>2012-04-21 12:17:51 +0200
commit3da2b530aff28d4ea0272e36578188bb6869cbcc (patch)
tree61923eb8c4d725c38e314e706740362a66c01021 /guides/code
parent504ba12e8cd256b08a43f8ee56c6e2b0272ce6cc (diff)
downloadrails-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')
-rw-r--r--guides/code/getting_started/app/controllers/posts_controller.rb1
-rw-r--r--guides/code/getting_started/app/views/posts/_form.html.erb10
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 %>