From 3da2b530aff28d4ea0272e36578188bb6869cbcc Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Sat, 21 Apr 2012 12:17:51 +0200 Subject: Add validation code to getting started guide and improve validation section --- .../code/getting_started/app/controllers/posts_controller.rb | 1 + guides/code/getting_started/app/views/posts/_form.html.erb | 10 ++++++++++ 2 files changed, 11 insertions(+) (limited to 'guides/code') 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? %> +
+

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

+ +
+ <% end %>

<%= f.label :title %>
<%= f.text_field :title %> -- cgit v1.2.3