aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJoseph Pecoraro <joepeck02@gmail.com>2009-05-30 00:53:32 -0400
committerJoseph Pecoraro <joepeck02@gmail.com>2009-05-30 00:53:32 -0400
commitece603cdf9ce20cf6acd84b3df669c5d516de2d3 (patch)
treee2ee726c664113cb6bb6b7c6772af0631be3cff4 /railties
parentc9d7affd8c5da5326eeed9df86ea5b46dc02faa7 (diff)
downloadrails-ece603cdf9ce20cf6acd84b3df669c5d516de2d3.tar.gz
rails-ece603cdf9ce20cf6acd84b3df669c5d516de2d3.tar.bz2
rails-ece603cdf9ce20cf6acd84b3df669c5d516de2d3.zip
Added TIP about resources when using the short form_for syntax.
Diffstat (limited to 'railties')
-rw-r--r--railties/guides/source/form_helpers.textile2
1 files changed, 2 insertions, 0 deletions
diff --git a/railties/guides/source/form_helpers.textile b/railties/guides/source/form_helpers.textile
index 0958c2c76a..b3ffc48e55 100644
--- a/railties/guides/source/form_helpers.textile
+++ b/railties/guides/source/form_helpers.textile
@@ -292,6 +292,8 @@ form_for(:article, @article, :url => article_path(@article), :method => "put")
form_for(@article)
</ruby>
+TIP: Declaring a resource will automatically generate the +*_path+ functions above. The short syntax expects such a function to exist based on the model of the object it is acting on. To declare a model as a resource, add the model to the resources list in the routes file +config/routes.rb+ like so: <pre>map.resources :articles</pre> Declaring a resource has a number of side-affects. See "Rails Routing From the Outside In":http://guides.rubyonrails.org/routing.html#restful-routing-the-rails-default for more information on setting up and using resources.
+
Notice how the short-style +form_for+ invocation is conveniently the same, regardless of the record being new or existing. Record identification is smart enough to figure out if the record is new by asking +record.new_record?+. It also selects the correct path to submit to and the name based on the class of the object.
Rails will also automatically set the +class+ and +id+ of the form appropriately: a form creating an article would have +id+ and +class+ +new_article+. If you were editing the article with id 23, the +class+ would be set to +edit_article+ and the id to +edit_article_23+. These attributes will be omitted for brevity in the rest of this guide.