Iterating My Way Forward – User Authentication Is Still A Bitch

My project reached the point that I have built a bunch of what is essentially scaffolds, but by hand, and understanding them, and had to bite the bullet and actually make it do something.

Ugh.  I can feel the pressure setting in.

Knowing… no understanding the relations of how you create a new function in a controller and it needs (maybe) a new view file, and all that stuff is one thing, but having to make it do things is a whole different thing.

Luckily I’ve got one more delaying tactic availble to me before I get to far.  User authentication.  The bane (I think) of rails. Hell, this is a new and hardly read or written blog and I’ve written about it two times.

Luckily I found this, while dated, very nice tutorial on Simple User Authentication. What resonated most with me was him talking about how he’s tried a bunch of different plugins (I have a bunch installed already) and has always ended up writing it himself from scratch.  I can definitely relate.  I also (as a newbie) like the idea of understanding everything that’s going on (or mostly everything anyway).

Of course, before I could do this (remember, I said I was good at delaying) I had to do some refactoring.  When I first started this referee management project, I have the model for the referee themselves, and the model for the “assignors”.  I started realizing that this is a bad design for all the obvious reasons.

So I did some copy and paste, some find and replace, and my carefully crafted “referee” and “assignor”models, controllers and views were re-created as a “user” model/views/controller and a “role” model which will, theoretically allow me to differentiate between the different user roles.

However, there are still challenges.  For one thing, I have two different users that I have to extend where they get logged into and what they can do through a single controller.  Also all these users are controlled by (currently) a different type of user still, the “admin” user, which in theory adds/edits/deletes the referee and assignor users.  But is that now creating more non-DRY code?

I have to keep on reminding myself to do one thing at a time, get it working, and then move on, and not think 10 moves ahead when things may or may not work.

Next up will be unit testing with rspec, which should be fun, as as a Perl programmer I did almost no testing at all.

Related posts (maybe):

  1. Better Way To Do Dynamic Methods
  2. Rails Authentication In a Gist

2 Responses to “Iterating My Way Forward – User Authentication Is Still A Bitch”

  1. curtismchale Says:

    seems like there is an opportunity for you to write a plugin here that suits the needs you have. Now don’t let that enable your procrastination.

  2. alan Says:

    Yup, funnily enough I was planning to clean it up and put it up as a gist. Thing with plugins are there are a billion of them out there already for this, and for me, an example I can just use and apply to the current situation was *much* easier to use/follow than a plugin or gem, as those “feel” like there’s a bunch of things hidden that you need to know about and dig into. Having it all just available to cut/paste (for me) was much nicer.

Leave a Reply