1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Using Yahoo! UI to Give Your Blog That "Blog Look"


8 of 10

Rendering the Partial

Once the partial is in place, the index.html.erb view becomes all of two lines of code. Calling the partial on an entire collection of Posts is trivial, plus a link to create a new post at the bottom.

# File: index.html.erb
<%= render :partial => 'post', :collection => @posts %>

<%= link_to 'New post', new_post_path %>

One final edit is required. Replace the contents of show.html.erb with a call to the partial. This makes the Posts controller completely DRY as far as displaying posts is concerned. If, in the future, you need to display a post in any other action, simply call the post partial. Later, if you wish to edit how a post is displayed, edit the post partial and it will be edited everywhere posts are automatically displayed.

# File: show.html.erb
<%= render :partial => 'post', :object => @post %>
  1. About.com
  2. Technology
  3. Ruby
  4. Ruby on Rails
  5. Rendering the Partial

©2014 About.com. All rights reserved.