Rails Document Manager Tutorial – Part 1

Being married to one of those academic types is rough.  I can handle the 15-syllable words and the excited recaps of various studies, but amount of literature that one man can claim to read is amazing.  Ben has access to thousands of psychology journal articles and insists that he can not read them in electronic form, so he prints them out.  In addition to wreaking havoc on the environment this has turned his half of our home office in to a complete and utter mess.  We’ve done everything we can think of to help him organize his literature, but the problem is sometimes he just doesn’t have time to file away each article appropriately.  My unbelievably organized husband would rather dump new articles in an empty box and then move on to a new box once the current one gets full.  This is all great, until Ben needs an article that he is *sure* he read last year or the year before.  Insertion went fabulously, but searching is a whole other story.  Searching for a journal article about cognitive something or the other is an O(n) algorithm around here.

So, we need a solution.  I told a friend of mine about this dilemma a while back and he suggested using it as an opportunity to learn about Ruby on Rails, but I never really got around to it.  Since then I’ve had other opportunities to mess with Rails, but since the problem still exists I think it is high time I came up with a solution!

I hope to document my solution in hopes of not only learning more myself, but also to maybe create a super simple tutorial for someone else who may need it.  I’ll try to be as detailed as possible…  we’ll see how it goes :o )

Getting Started

First, Ben and I needed to come up with a reasonable way to store these articles.  I suggested having him enter information about each article as soon as he prints it out, but that led to divorce threats.  So, we decided that we’d foster his habit of just throwing articles into boxes, however, he’d also number each article and box.  That way, he can tell the app that articles 150 – 300 are in box 2.  Later, when he has the time and motivation, he can go back and tell the app little bit about articles 150 – 300.  He’ll want to tell it the name of the journal and issue number where the publication appeared, the author(s) and maybe some keywords.

In order to prevent me from constantly writing queries to answer questions like “Which boxes should I check if I want a lot of articles about forensic assessment of juveniles?”, I’ll probably add a reporting layer as well.  But, that’s getting ahead of myself :o )

Planning

So, now I need to plan out my entities.  Here’s a quick ERD of what I’m thinking:

And from that, here’s a relational model:

I think most of that should be self explanatory except for why I chose to have three separate attributes to make up the date in the issues relation.  Ben said that sometimes issues don’t have an exact date, they just have a month and a year.  Rather than hacking stuff up and setting the date to the first of the publication month or something, I figured the three separate attributes would be a good solution.

Create the application and start the webserver

C:\Users\Tina\workspace>rails articles
C:\Users\Tina\workspace>cd articles
C:\Users\Tina\workspace\Articles>ruby script\server

Start setting up Models, Views and Controllers

I’m going to use scaffolding to generate my entities that will need views…  Basically, it’s just the following syntax:

ruby script\generate scaffold <entity> <attribute1>:<datatype1> <attribute2>:<datatype2>

C:\Users\Tina\workspace\Articles>ruby script\generate scaffold journal name:string
C:\Users\Tina\workspace\Articles>ruby script\generate scaffold issue journal_id: integer month:integer day:integer year:integer
C:\Users\Tina\workspace\Articles>ruby script\generate scaffold article issue_id:integer box_id:integer name:string start_page:integer end_page:integer number:integer
C:\Users\Tina\workspace\Articles>ruby script\generate scaffold author first_name:string middle_initial:string last_name:string
C:\Users\Tina\workspace\Articles>ruby script\generate scaffold keyword word:string
C:\Users\Tina\workspace\Articles>ruby script\generate scaffold box number:integer

Migrate the database

Before doing any database migrations, sqlite needs to be installed with the ruby gem.  This is a good explanation of how to do so: http://wiki.rubyonrails.org/rails/pages/HowtoUseSQLite 
To install the gem I used the following:
C:\Users\Tina\workspace\Articles>gem install --version 1.2.3 sqlite3-ruby

To do the DB migration (create the DB and tables based on the scaffolding), just run the following command:
C:\Users\Tina\workspace\Articles>rake db:migrate 

Yay!!!
I can now enter journals, articles, etc.  Yippee!  However, this isn’t anywhere near usable.  None of my mapping tables are being populated and I highly doubt anyone wants to look up an issue’s id in order to enter a new article.  That’ll all be handled in Part 2! 

2 Comments »

Tina on December 14th 2008 in Development

Eclipse and Subversion

I wanted to commit the DB diagrams and scripts I’ve created to our SVN repo but I had a little trouble connecting with Eclipse 3.4/Subclipse.  I kept getting the error “svn: Can’t create tunnel: The system cannot find the path specified.”  I found a few forum posts suggesting switching to the JavaSVN(Pure Java), but that wasn’t showing up under Window -> Preferences -> Team -> SVN -> SVN Interface -> Client.  I installed the SVNKit plugin, but that didn’t help.

I decided to try using the Subversive plugin instead.  My new problem was that I had no connectors under Window -> Preferences -> Team -> SVN -> SVN Connector.  I then found this post http://osgi.mjahn.net/2008/08/27/getting-svn-running-under-eclipse-34-ganymede/, added http://www.polarion.org/projects/subversive/download/eclipse/2.0/update-site/ as a Eclipse update site and downloaded a connector.  Everything seems to be working!  I am using the SVN Kit connector.

No Comments »

Tina on November 22nd 2008 in Development