Hi, thanks for responding.
That's my intent.
It's not shown in config/routes.rb currently:
get "about" => "pages#about"
get "admin" => "pages#admin"
resources :athletes do
The get :all isn't used. At present it's redundant code as simply returning to index page does the same thing.
It's my desire that 2 of the coaches (being myself and my business partner in the UK) be designated as admin^ and that the sign_up page be accessible to an admin person.
For instance we might bring a new coach onto the team and I need for my partner to be able to add a new coach to the user (coach) model without need to do command line interaction with the database^^.
^ I might just create a separate admin sign in, as the views change when you are an admin (e.g. all athletes are viewable in the index page), and sometimes I just want to work as a coach focussed on my own athletes, and not perform admin functions. That might need more controls as it would be helpful for us both to be able to be logged in at same time with admin level views if we are discussing overall business matters via skype.
^^ I also need to think through the admin being able to reassign athletes to another coach. Sometimes it happens we move an athlete to a different coach. Or perhaps we want to make another coach an admin.
This is what I'd like to do and is where I'm struggling. routes.rb file is shown above and there are three controller files:
It's not clear to me where such a controller would go or what it would look like. Would it be in the pages_controller.rb file? Not much in there at present:
class PagesController < ApplicationController
home points to nowhere/doesn't exist, and about and admin point to static pages at present.
Yes, that's the relationships between the models. Thanks for the suggestion, will give it a try. Does the order of the various parameters matter?
I'm not yet up to speed on how this code works yet, so the differences in how it can be written elude me. I'm at the stage of just finding what works and using it. I'll get better as I learn what's actually going on.
Almost. I have the current_coach scopes working now - and the code above was part of it. It took a while to adapt the demonstration in the video so it behaved as I wanted. I'll have more scopes to add as I go, e.g. sorting, or highlighting which athletes training plans are due/overdue, that sort of thing. Will need a few more fields in the athlete model for that stuff.
However I have a problem with Admin being unable to view the show or edit pages for an athlete for whom they are not the current_coach.
I suspect the before_action statements in the athletes_controller.rb file are preventing an admin from performing those actions and I need to somehow modify them to allow admin access as well. e.g. I tried adding some code to the definition of correct_coach but messed it up and ditched it. This is current code:
class AthletesController < ApplicationController
before_action :set_athlete, only: [:show, :edit, :update, :destroy]
before_action :correct_coach, only: [:show, :edit, :update, :destroy]
before_action :authenticate_coach!, except:  #authenticate coach is logged in for user action
# Use callbacks to share common setup or constraints between actions.
@athlete = Athlete.find(params[:id])
@athlete = current_coach.athletes.find_by(id: params[:id])
redirect_to athletes_path, notice: "Not authorised to edit this athlete" if @athlete.nil?
# Never trust parameters from the scary internet, only allow the white list through.
permit(:name, :sex, :birthdate, :coaching_level, :date_commenced, \
:current_client, :country, :country_code, :email)