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
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
app/overrides/add_tasks_list_to_dashboard.rb
Deface::Override.new(:virtual_path => "blast/dashboard/index",
:name => "add_tasks_list_to_dashboard",
:insert_after => "[data-blast-hook='dashboard']",
:partial => "overrides/dashboard_tasks_list",
:namespaced => true)
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
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
</div>
<table class="table">
<thead>
<th>ID</th>
<th>Title</th>
<th>Content</th>
<th>Created On</th>
</thead>
<tbody>
<%- current_user.tasks.limit(3).each do |task| %>
<tr>
<td><%= task.id %></td>
<td><%= task.title %></td>
<td><%= task.content %></td>
<td><%= task.created_at.strftime("%d %b. %Y") %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="panel-body text-center">
<%= link_to '...', tasks_path %>
</div>
</div>
</div>
Once again,
git status
git add .
git commit -m "Extending the Dashboard"
git push origin Chapter-17
In this chapter we extended the Dashboard to display the last 3 tasks.
Just like with the Contacts
module, we have an exercise for you.