Archive

Trouble with Rails

This weekend I thought I would have a go at throwing together a Rails front end to my mythtv database. I thought this would be easy but it seemed to highlight one difficulty after another with using Rails with a so called “legacy” application (one that already exists and not designed for Rails).

To start with I used the Rails install that comes with OS X. I did something like 

rails mythrails
cd mythrails
#edit database.yml
ruby script/generate scaffold Program program

Since this is a so called legacy application you need to edit config environment.rb to tell rails not to pluralize table names

ActiveRecord::Base.pluralize_table_names = false

and edit the model to tell it what the table is actually called

class Program < ActiveRecord::Base
  set_table_name "capturecard"
end

then starting the web server gives you a web interface to the program table. It’s really simple. But …

If you try to edit the data or create a new entry it will complain because (I think) there is no id field in the program table. This lead me to discover that you can add something like

class Program < ActiveRecord::Base
  set_table_name "capturecard"
  set_primary_key "the_id_field"
end

This raises the next problem. Rails can not cope with composite primary keys. You need to install composite_primary_keys. However, this leads to the next issue - composite_primary_keys needs Rails 2. This then has the side effect that generating the scaffold no longer works. In Rails 2 you need to specify the fields and types for all the fields in the table. In the case of a legacy system the table already exists so why can’t the scaffold generator just read the fields from the database?

At this point I gave up. I am sure this is not too hard to work around but I only wanted to play and this all seemed like it was getting harder than I ever intended.

New K2 style

I was playing with styles in the K2 theme I am using. I came across blackboard which I think looks quite nice. Everything worked fine except the sidebar (to the right) that kept appearing at the bottom of the page (but still over to the right) below the last post. I was able to fix it by changing the blackboard css so that the margin property in the following 

.secondary {
  font-size: 1em;
  line-height: 1.5em;
  padding: 10px 0;
  margin: 0 0 20px 71%;
  width: 26%;
  color: #666;
  position: relative;
  }

looked like this

margin: 0 0 20px 0%;

Now this is the first time that I have played with CSS so apart from the fact that this is changing the margin-left value I don’t really understand what I did.

Elastic IP addresses

Amazon have added static IP addresses to their EC2 system. I have been meaning to try EC2 out for a while. I might just do it now.

Mutliple displays on MacBook Pro

Display Link have released beta drivers that allow you to use up to 4 USB connected displays on your MacBook Pro.

Airport Extreme

I have never had much luck getting good wireless reception in my house. Until now I have used the wireless access point built in to my ADSL router. I have tried products from Vigor, Linksys and Dlink and reception has always been terrible unless you are working in the same room as the access point. Even in the lounge, one room away from the access point, through a thin partition wall (it used to be all one room) I could only get intermittent reception at best.

So today I gave in and got an Apple Airport Extreme. I should have known that Apple would make yet another great product. First impressions are that I now have a strong, reliable signal throughout the house and what is more it was a pleasure to configure. Compared to the web pages in the Linksys and Vigor products I have tried the Apples Airport Utility is really simple, well designed and as with all Apple stuff it “just works!”