RoboProg's / Software Development
I had some hardware problems this week (involving a broken laptop), so I have not had any "quiet time" to do any development this week. Instead, I think I will share some reading, as well as listening, that I have been doing.
First, the listening. I would like to thank Paul Williams (who really should put something on his site, hint, hint) for introducing me to the IT Conversations site. There are podcasts for a variety of topics available there. I spend a lot of time in the car commuting every day, so it is useful to have something else to listen to besides the radio. In particular, some keynote speeches from past RailsConfs are there. Several of these I found interesting for my own contrary way.
One of these is about comparing Ruby to Smalltalk, and some of the implementation history that Ruby is likely to repeat. Also of interest in this discussion is some talk of making very stateful application code and using the objects themselves as the persistance mechanism. Perhaps there are some situations in which such an iconoclastic approach would be what was needed to simplify a problem.
The other that I found intriguing was about Sun's support for Ruby, such as adopting the JRuby project (which is faster than ruby 1.8), and providing a Ruby plugin for Netbeans. If anybody gets a chance to try the netbeans IDE with ruby, please let me know how that goes. Also, in regards to speed, if you poke around on the debian shootout page, you may notice that Ruby seems to prefer small code and a small memory footprint, while Java prefers to run fast (and use gobs of memory).
I have been reading through the book Enterprise Rails. FWIW, you can get it Amazon for quite a bit less than I did. Too bad I don't get paid for the link. One of the things I liked about this book was the use of PostgreSQL, rather than the seemingly obligatory MySQL. I have been using Postgres at home since late 2000. It is reasonably comparable to Oracle. That other thing was definitely not then, and I'm not so sure it is now, either. I guess I am not the only person who prefers to use PostgreSQL, either.
The early part of the book focuses on building a good data model, and some guidelines to make sure the data is in a reasonably (3rd) normalized form, before charging in and generating a bunch of boilerplate MVC code. It also briefly covered writing your own plugins as a way to standardize whatever hacks you need to add to Rails for your project. I will probably have more to say about the book in the near future, if not next week.
It turns out that the initial setup of Acts_as_authenticated is relatively easy. By the way, I am using Ubuntu this year (rather than Red Hat or Slackware, in years past), which uses the Debian package management system, so I have kept notes in terms of that system. First, some prerequisites:
(even though I use Subversion this year, rails needs Git)
Still with me? You now have the packages needed, and you are ready to add the basic login setup to your project!
This is what I had to do to get the login stub code up and running:
If you commit the plugin installation and generation in subversion (at the same time), you will see changes something like the ones shown below. I have culled out the file header lines from a "diff" listing as an after the fact "status" command.
Note that revision 3 was the revision that committed these changes, thus the "-r 2:3" argument. The timestamp in your migration script will of course differ as well.
is something specific to my application.
Your controller(s) will have different names.
The next time you start your application,
any requests to the updated controllers will force a trip to the login page.
/account/signup URI to create a new login
(or add a link to it in appropriate places)
For what it's worth, you can see what I have done so far here. Of course, it probably will not work well unless you do this first. Also, be aware that this site is far from done, and I will likely have to frequently remove the "vandalism" until things settle down. So, along that line of thought, what's next?
I have been playing around with Ruby on Rails for a few months, here and there, as an alternative to the J2EE ("it's the new COBOL") stuff that I do at work. Most of the examples / books / tutorials that I have read so far focus on getting a CRUD system up and going to edit a table. This is pretty easy to do, and doubtless explains the popularity of Rails.
The problem is, as soon as you want to deploy ANYTHING, you need some kind of login mechanism to keep the riff-raff out, and to force people to accept spam from you, and all that good stuff.
Poking around a bit quickly reveals that Rails controllers have a session object (or at least something that quacks like one), like just about every other web app framework in the world. Well, that's good. It would sure be nice to associate a session with a persistant identity of some kind (hey, maybe even with some roles, eventually, why not).
Never fear! We have a solution. Well, if by "a solution", you mean "several available plugins", or numerous articles about rolling your own. Out of the box, Rails has no default login mechanism included. The books I have put this topic off until far too late, in my opinion. After searching around some, it looks like the best solution (or at least the most widely recognized one, since I am not in a position to compare them from experience) is "acts as authenticated".
I will probably have more to say on this next week. Keep in mind, there also seems to be quite a bit of thrashing going on, as Rails 2.x is still relatively new. Note: "about a year" is "new" to oldsters like me who do not resync their libraries every week, OK? It is also relatively new in relation to printed, coherent tutorial material that you can purchase. Even on line, much of what you google into is still written in terms of 1.x.
Yes, I know it's trivial if you personally have already done it.
Oh, and I'm now being threatened with "git", just when I was getting the hang of subversion. Subversion really does work well with Rails, by the way, as I am just too lazy to track all the files that Rails creates individually. (I know this must violate some ethic, but I only have so much time at home)