5. Create partials

September 2015 · 2 minute read

Keep watching to see how I build My budgeting app.

What are partials? Partials in rails are views which enable you to create layouts with multiple content sections. I am going to nest three content partial views within the right hand column (also a partial) of my app to render a budgets summary section which will each eventually draw information from different models.

Running through the creation of a new right hand column partial to follow on from my last tutorial, I will first create the new file _rightcolumn.html.erb under app/views/welcome.

Adding the line of Ruby seen here on line 18 in app/views/welcome/index.html will render my new partial on the right hand side of the screen.

<div class="row">
  <div class="col-md-8">
    <%= render "welcome/leftcolumn"%>
  </div>
  
  <div class="col-md-4">
    <%= render "welcome/rightcolumn"%>
  </div>
</div>

In the new _righthand column partial, I have put in a header “Projections” as this is where my budget summary will be.

# Projections 

<div class="row">
  <%= render "welcome/next_pay_day"%>
</div>

As you can see in lines 3-5, I have also rendered another partial called _next_pay_day.html.erb which was created in the same way as above.

Next_pay_day will show summary calculations for the next pay day. This model will be replicated for End_of_month and End_of_year as well.

The _next_pay_day.html.erb partial contains the following HTML to render a summary table. Again, this model will be the same for End_of_month and End_of_year summaries too.

## Next Pay Day

<table>
  <tr>
    <td>
      Pay
    </td>
  </tr>
  
  <tr>
    <td>
      Balance
    </td>
  </tr>
  
  <tr>
    <td>
      Credit Card Repayments
    </td>
  </tr>
  
  <tr>
    <td>
      Savings
    </td>
  </tr>Excess Cash
</table>

Now the app is starting to come together with an overall base view and layout.

Keep watching, in the next tutorial I will be using posgreSQL and Rake Migrations to create some data storage.

*Reference