diff options
author | Oscar Del Ben <info@oscardelben.com> | 2012-04-25 13:18:59 +0200 |
---|---|---|
committer | Oscar Del Ben <info@oscardelben.com> | 2012-04-25 13:18:59 +0200 |
commit | ccbd32c294bf685a389d456164a12fd777756873 (patch) | |
tree | 86e31c6ccd399ba4ff2e70e1b6c0b0f7952d8827 /guides | |
parent | 6f0929110464b40072b62cb1c55a0589059fe593 (diff) | |
download | rails-ccbd32c294bf685a389d456164a12fd777756873.tar.gz rails-ccbd32c294bf685a389d456164a12fd777756873.tar.bz2 rails-ccbd32c294bf685a389d456164a12fd777756873.zip |
Add partials explanation to getting started guide
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/getting_started.textile | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 78e9761570..88d5ce6d9b 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -899,6 +899,37 @@ And here's how our app looks so far: !images/getting_started/index_action_with_edit_link.png(Index action with edit link)! +h4. Using partials to clean up duplication in views + ++partials+ are what Rails uses to remove duplication in views. Here's a +simple example: + +<erb> +# app/views/user/show.html.erb + +<h1><%= @user.name %></h1> + +<%= render 'user_details' %> + +# app/views/user/_user_details.html.erb + +<%= @user.location %> + +<%= @user.about_me %> +</erb> + +The +show+ view will automatically include the content of the ++_user_details+ view. Note that partials are prefixed by an underscore, +as to not be confused with regular views. However, you don't include the +underscore when including them with the +helper+ method. + +TIP: You can red more about partials in the "Layouts and Rendering in +Rails":layouts_and_rendering.html guide. + +Our +edit+ action looks very similar to the +new+ action, in fact they +both share the same code for displaying the form. Lets clean them up by +using a +_form+ partial. + h4. Using the Console To see your validations in action, you can use the console. The console is a |