Pushing Through The Wall
This entry was almost titled “In Which it All Comes Apart” because lately I’ve felt like all my previous forward motion with my Rails project has come to a crashing halt. It seemed like the only time that I got work done was at the FV.rb meetups, but in the evenings I just didn’t have any drive to do anything, and on the weekend when I did, I’d think about the current couple of tasks on my plate and get… scared is about the only real word for it, and just go back to watching TV, websurfing, or whatever other thing that wasn’t programming Ruby and Rails. Not a good way to go.
Last night I finally broke through this a bit. Amidst my mother-in-law drilling and cutting (she’s helping my wife put up cabinets) and my brother-in-law on the couch oohing and awwing over heavy equipment ads on craigslist, I managed to get things done. I figure a bit of post-mortem might help me for the next time it happens.
The two things that I had on my plate were not, in fact, the only things needing to be done, but they were the two things that are fairly isolated and sort of simple.
The first was adding ‘areas’ to my referee site. Each club has many fields, each field has many games. I wanted to expand this so that each club has many areas, and each area has many fields, and so on. Basically this allows you to break up the “Langley” club into say, north south east and west, and assign users to various areas and make things a bit more manageable. IE: Assignor Bob manages the north zone, while Manager Sue takes care of South and East.
Code wise it’s pretty simple, add a new model, add the “has_many” and “belongs_to” relationships, and create the management pages. Simple stuff, so what’s the problem?
I think it might have come into the testing part again. Because I’d have to rearrange some of my queries to ensure that users get the right games from the right fields from the (now) right areas from (breath) the right club, having no testing set up means that I’d have to go to all the pages that access that code, redo the queries, re-test, etc. Ugh.
The second task that was a real stumbling block was the user and role management. I had set up user authentication a while back, and if you log in as one of two user types you’d end up being sent to the “correct” page, and the two different controllers (/bids and /assignments) are protected through a before_filter as well, but I hadn’t gotten around to “Management” stuff (editing games, fields, etc) yet.
The big mental block that I had in this area was that I had 3 fairly clearly defined roles, 4 if you include the “unauthenticated” users. I had
- Referee (can bid on games)
- Assignor (approves/edits referee bids)
- Club Admin (club management stuff)
All the stuff in the User model is geared towards these, a club_id is defined and required, email is required, etc.
The role that wasn’t so easily defined was the “master” admin. This is the main user that would manage the whole site, set up clubs, and basically have access to everything. I faced the challenge of either creating a new type of authentication and model (ignoring the DRY principle), putting a bunch of exceptions in (ie: requires validation of club_id unless this user has a role type of ‘masteradmin’) and making things ugly.
I managed to push through the first one, or at least start to. I’ve managed to get to the scaffolding part anyway. Also in my lunch hours I’ve started going at the failing tests too. That’s a whole other blog post though, probably involving me going back to the simplest cases that are in the Rails Tutorial book and figuring out how to deal with speccing out password protected pages