Chapter 17

The Tasks Module: Extending the Dashboard

Well that’s it! You know everything about extending and working with different engines. Let’s wrap up this module by adding a list of tasks to the dashboard view.

Before we begin, let’s create our chapter branch:

git checkout -b Chapter-17

17.1. Tasks in the Dashboard

17.1.1. Add the override

Let’s create the Deface override to insert our Tasks in the dashboard (you probably don’t need a reminder that you should be doing this from the Tasks engine):

touch app/overrides/add_tasks_list_to_dashboard.rb
Listing 0.1: Contents of tasks lists override app/overrides/add_tasks_list_to_dashboard.rb => "blast/dashboard/index",
                     :name => "add_tasks_list_to_dashboard",
                     :insert_after => "[data-blast-hook='dashboard']",
                     :partial => "overrides/dashboard_tasks_list",
                     :namespaced => true)

17.1.2. Add the override view

And now let’s create the view that displays the last 3 tasks created:

touch app/views/blast/tasks/overrides/_dashboard_tasks_list.html.erb
Listing 0.2: Contents of tasks lists override view app/views/blast/tasks/overrides/_dashboard_tasks_list.html.erb
<div class="col-md-6">
  <div class="panel panel-primary">
    <div class="panel-heading">
      Last 3 Tasks
    <table class="table">
        <th>Created On</th>
        <%- current_user.tasks.limit(3).each do |task| %>
          <td><%= %></td>
          <td><%= task.title %></td>
          <td><%= task.content %></td>
          <td><%= task.created_at.strftime("%d %b. %Y") %></td>
        <% end %>
    <div class="panel-body text-center">
      <%= link_to '...', tasks_path %>

17.1.3. And for some pretty pictures

Let’s see if everything worked:
Figure 1: Seems to be working... nice!

17.2. Pushing Our Changes

Once again,

  1. Check the changes:
    git status
  2. Stage them:
    git add .
  3. Commit them:
    git commit -m "Extending the Dashboard"
  4. Push to your GitHub repo if you’ve configured it:
    git push origin Chapter-17

17.3. Wrap Up

In this chapter we extended the Dashboard to display the last 3 tasks.

17.3.1. Next Step

Just like with the Contacts module, we have an exercise for you.