From 0b41aa9b2c8ad6b06c1e919068ffc0e1d6b0e6f5 Mon Sep 17 00:00:00 2001 From: rohit Date: Fri, 30 Apr 2010 12:09:53 +0530 Subject: fixes to tags section --- railties/guides/source/getting_started.textile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'railties/guides/source') diff --git a/railties/guides/source/getting_started.textile b/railties/guides/source/getting_started.textile index 0f4324d9a5..5ee8a4626c 100644 --- a/railties/guides/source/getting_started.textile +++ b/railties/guides/source/getting_started.textile @@ -1261,7 +1261,7 @@ Now if you try to create a new post, you will be greeted with a basic HTTP Authe h3. Building a Multi-Model Form -Another piece of your average blog is the ability to tag posts. This requires that your application edits more than one thing on a single form. Rails offers support for nested forms. +Another feature of your average blog is the ability to tag posts. To implement this feature your application needs to interact with more than one model on a single form. Rails offers support for nested forms. To demonstrate this, we will add support for giving each post multiple tags, right in the form where you create the post. First, create a new model to hold the tags: @@ -1298,7 +1298,16 @@ We will modify +views/posts/_form.html.erb+ to render a partial to make a tag: <% @post.tags.build %> <%= form_for(@post) do |post_form| %> - <%= post_form.error_messages %> + <% if @post.errors.any? %> +
+

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

+
    + <% @post.errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %>
<%= post_form.label :name %>
@@ -1321,9 +1330,9 @@ We will modify +views/posts/_form.html.erb+ to render a partial to make a tag: <% end %> -This example shows another option of the render helper, being able to pass in local variables, in this case, we want the local variable +form+ in the partial to refer to the +post_form+ object. +Note that we have changed the +f+ in +form_for(@post) do |f|+ to +post_form+ to make it easier to understand what is going on. -You will also note that we also have changed the +f+ in form_for(@post) do |f| to post_form to clarify what is going on somewhat. +This example shows another option of the render helper, being able to pass in local variables, in this case, we want the local variable +form+ in the partial to refer to the +post_form+ object. We also add a @post.tags.build at the top of this form, this is to make sure there is a new tag ready to have it's name filled in by the user. If you do not build the new tag, then the form will not appear as there is no new Tag object ready to create. -- cgit v1.2.3