Commit 5eb775c
Changed files (2)
app
controllers
views
workouts
app/controllers/workouts_controller.rb
@@ -1,6 +1,7 @@
class WorkoutsController < ApplicationController
def index
- @workouts = paginate(recent_workouts, per_page: 24)
+ @exercise = Exercise.find_by(name: params[:exercise])
+ @workouts = paginate(recent_workouts(@exercise), per_page: 24)
end
def new
@@ -36,8 +37,12 @@ class WorkoutsController < ApplicationController
)
end
- def recent_workouts
- current_user.workouts.recent.includes(:routine)
+ def recent_workouts(exercise)
+ if exercise.present?
+ current_user.workouts.recent.includes(:routine).with_exercise(exercise)
+ else
+ current_user.workouts.recent.includes(:routine)
+ end
end
def find_routine(routine_id)
app/views/workouts/index.html.erb
@@ -3,6 +3,18 @@
<div class="columns">
<div class="column is-12">
<% exercises = ["Squat", "Bench Press", "Barbell Row", "Overhead Press", "Deadlift"] %>
+ <div class="tabs">
+ <ul>
+ <li class="<%= 'is-active' if @exercise.nil? %>">
+ <%= link_to 'All', workouts_path %>
+ </li>
+ <% exercises.each do |name| %>
+ <li class="<%= 'is-active' if name == @exercise.try(:name) %>">
+ <%= link_to name, workouts_path(exercise: name) %>
+ </li>
+ <% end %>
+ </ul>
+ </div>
<table class="table is-striped">
<thead>
<tr>