aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc
diff options
context:
space:
mode:
authorJames Miller <james@jkmillertech.com>2008-09-21 08:32:34 -0700
committerJames Miller <james@jkmillertech.com>2008-09-21 08:32:34 -0700
commit860efecd8f44e112e447f4a233115090bdd8c3db (patch)
tree2a6224a27eda4b2553bc8cdc2ea9b3009767c20c /railties/doc
parentd9b67223e07e91ceed9da1f4f7d23aa6ef5ed27a (diff)
downloadrails-860efecd8f44e112e447f4a233115090bdd8c3db.tar.gz
rails-860efecd8f44e112e447f4a233115090bdd8c3db.tar.bz2
rails-860efecd8f44e112e447f4a233115090bdd8c3db.zip
New and create actions
Diffstat (limited to 'railties/doc')
-rw-r--r--railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt32
1 files changed, 31 insertions, 1 deletions
diff --git a/railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt b/railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt
index 2805e5629d..c181d1432c 100644
--- a/railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt
+++ b/railties/doc/guides/getting_started_with_rails/getting_started_with_rails.txt
@@ -317,7 +317,37 @@ This time, we're setting `@post` to a single record in the database that is sear
==== New & Create
-Description of new and create actions
+In your controller, you'll see the `new` and `create` actions, which are used together to create a new record. Our `new` action simply instantiates a new Post object without any parameters:
+
+-----------------------------------------
+def new
+ @post = Post.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @post }
+ end
+end
+----------------------------------------
+
+Our `create` action, on the other hand, instantiates a new Post object while setting its attributes to the parameters that we specify in our form:
+
+----------------------------------------
+def create
+ @post = Post.new(params[:post])
+
+ respond_to do |format|
+ if @post.save
+ flash[:notice] = 'Post was successfully created.'
+ format.html { redirect_to(@post) }
+ format.xml { render :xml => @post, :status => :created, :location => @post }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
+ end
+ end
+end
+---------------------------------------
==== Edit & Update