aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan Bigg <radarlistener@gmail.com>2012-05-16 17:50:46 +1000
committerRyan Bigg <radarlistener@gmail.com>2012-05-16 18:05:35 +1000
commite91a1a0321bd12968cba3cfa504119e74c1caa2c (patch)
tree22188de1f34aace98ef4c2f6ca5dfde7c60cf74e
parent926e160ed0292240251c481e6fdef3ea14e139bc (diff)
downloadrails-e91a1a0321bd12968cba3cfa504119e74c1caa2c.tar.gz
rails-e91a1a0321bd12968cba3cfa504119e74c1caa2c.tar.bz2
rails-e91a1a0321bd12968cba3cfa504119e74c1caa2c.zip
[getting started] re-add new action back to PostsController, explain that it'll be explained in a short while
-rw-r--r--guides/source/getting_started.textile16
1 files changed, 14 insertions, 2 deletions
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile
index 0d247d6299..5c418e3af6 100644
--- a/guides/source/getting_started.textile
+++ b/guides/source/getting_started.textile
@@ -685,9 +685,18 @@ format, and the existence of associated objects. Validations are covered in deta
in "Active Record Validations and
Callbacks":active_record_validations_callbacks.html#validations-overview
-With the validation now in place, when you call +@post.save+ on an invalid post, it will return +false+. If you open +app/controllers/posts_controller.rb+ again, you'll notice that we don't check the result of calling +@post.save+ inside the +create+ action. If +@post.save+ fails in this situation, we need to show the form back to the user. To do this, change the +create+ action inside +app/controllers/posts_controller.rb+ to this:
+With the validation now in place, when you call +@post.save+ on an invalid
+post, it will return +false+. If you open +app/controllers/posts_controller.rb+
+again, you'll notice that we don't check the result of calling +@post.save+
+inside the +create+ action. If +@post.save+ fails in this situation, we need to
+show the form back to the user. To do this, change the +new+ and +create+
+actions inside +app/controllers/posts_controller.rb+ to these:
<ruby>
+def new
+ @post = Post.new
+end
+
def create
@post = Post.new(params[:post])
@@ -699,7 +708,10 @@ def create
end
</ruby>
-Notice that we use +render+ instead of +redirect_to+ when +save+
+The +new+ action is now creating a new instance variable called +@post+, and
+you'll see why that is in just a few moments.
+
+Notice that inside the +create+ action we use +render+ instead of +redirect_to+ when +save+
returns +false+. The +render+ method is used so that the +@post+ object is passed back to the +new+ template when it is rendered. This rendering is done within the same request as the form submission, whereas the +redirect_to+ will tell the browser to issue another request.
If you reload