From 0d1fef7d2071afc57ce7790249b205fda0f3e24a Mon Sep 17 00:00:00 2001 From: Josh Atwell Date: Mon, 5 Jun 2017 06:21:19 +0000 Subject: [PATCH] adding devise filters to controllers, accidentally changed some on the master >.< --- app/controllers/dashboard_controller.rb | 1 + app/controllers/users_controller.rb | 1 + app/helpers/exercises_helper.rb | 7 +++++++ app/views/users/show.html.erb | 4 +++- 4 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 app/helpers/exercises_helper.rb diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index b0ff6c9..8ab216b 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,4 +1,5 @@ class DashboardController < ApplicationController + before_action :authenticate_user! def index @athletes = User.paginate(:page => params[:page]) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1259b6d..d21cbb9 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + include ExercisesHelper before_action :require_same_user, only: [:edit, :update] before_action :set_user, only: [:show, :edit, :update, :destroy, :finish_signup] diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb new file mode 100644 index 0000000..477cee3 --- /dev/null +++ b/app/helpers/exercises_helper.rb @@ -0,0 +1,7 @@ +module ExercisesHelper + + def exercise_owner? + owner_check(@exercises.user_id) + end + +end \ No newline at end of file diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index cda248e..3cccd45 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -110,7 +110,9 @@ No Workouts yet <%end%> - <%= link_to "New Workout", new_user_exercise_path(current_user), class: "btn btn-primary link" %> + <% if logged_in? and exercise_owner? %> + <%= link_to "New Workout", new_user_exercise_path(current_user), class: "btn btn-primary link" %> + <% end %> <%= content_tag :div, "", id: 'chart', data: {workouts: @exercises}, class: "chart" %>