Permissions problem with Rake on XP

by George on January 5, 2009

When starting out a new rails project on Windows XP, I ran into a strange problem. I usually do all my development on Mac OSX, but this week I had a need to set up a new project on a XP box. After creating my rails project and a few models. I ran rake db:migrate to set up my development database. All seemed to be going well until I tried to run autotest. Prior to running my test suite, I ran the rake task to set up my test data base with the following result.

> rake db:test:prepare

rake aborted!

 

Permission denied - db/test.sqlite3

(See full trace by running task with –trace)

The full trace was not much help either. I’m using SQLite in this case, so I thought there may be a problem with the db/test.sqlite3 file in my project. I checked the permissions and everything looked fine. I was even able to connect to the test.sqlite3 data base using the sqlite3 command line and add tables, insert records, etc. Finally I tried to delete the test.sqlite3 file thinking I would just re-create it. Then I get the message from XP telling me that the file can not be deleted because it is being used by another process. Ah ha! Apparently, Aptana Studio had a lock on the file which was causing rake to puke. I closed Aptana Studio and the rake task ran as expected. I did look to make sure that the file was not open in studio first and it was not. Looks like Aptana Studio gets another demerit on the chalkboard today.

{ 0 comments }

How to get Ruby working with SQLite on Windows

by George on December 21, 2008

I know, I know – it’s Windows. Step 1, buy a Mac. I do much of my development on a Mac, and it truly is much easier to set things up. Unfortunately, I don’t always have a choice where my code is developed or deployed. I recently needed to get SQLite working with my Ruby development environment on Windows XP. It was a huge pain that involved tracking down a few different errors, so I thought I’d list out what I came across to help out anyone else out there that is in the unfortunate situation of having to work with XP. [click to continue...]

{ 5 comments }

Aptana Studio crashing

by George on December 18, 2008

Well, I’m a little bit dissappointed. I’ve been using the new Aptana Studio 1.2.1 for a couple of days now, and there are apparently still some kinks to be worked out. I just had the studio crash on me again. That’s the second time today, and it happened once yesterday as well. There are no warnings, no errors, I just clicked on a file to open it, the application freezes up, and after about 10 seconds, it’s just gone. Like it never existed. And to make things even more painful, when I open it back up, it has forgotten several of the changes I’ve made. Any saved files are not lost, but any changes I’ve made to my workspace, perspectives, preferences and so on are just forgotten. I don’t think it’s a memory issue. I’ve seen the errors before that the memory filled up and you need to restart eclipse, but in these cases, I get nothing. I’ve experienced the same thing on both Windows XP and Mac OSX. Aparently the changes to preferences are only saved when you close Aptana (or eclipse), so now I just have to remember to shut down after every preference change . . . What a pain.

Another thing I’d really like to see one of these days is a better code formatter for Ruby and PHP. If you’ve ever used the Java code formatter, you’ve seen how many different options there are. But with Ruby and PHP, it’s quite minimal. I don’t want much more, but it would be nice for example to be able to specify which type of blocks you prefer do..end vs {} for example. And set better alignment when you have a long parameter list that breaks over multiple lines. Most of us like to do something like this:

my_spiffy_method param_one,
                 param_two,
                 param_three

Instead of this:
my_other_cool_method param_a,
param_b,
param_c

The later is what the Ruby editor in Aptana does for you.

{ 2 comments }

Aptana 1.2.1 release

by George on December 17, 2008

The good folks over at Aptana recently released their latest Aptana Studio. I’m checking it out tonight. Looks to be pretty promising so far. However, I did have a few issues with the install process. I tried to run the auto-updater and just update to the latest version, and it looked as if all were working. But then I kept getting strange errors even after a couple of restarts. It was unable to update my ruby gems for example. So I went about it a different way and actually uninstalled and reinstalled. Of course, now I have to go about moving all my projects over to my new workspace location. I know I could have kept my old workspace, but it was probably time to do some cleaning up in that area anyway.

I’m also going to try out the new Aptana PHP 1.0. I’ve been really enjoying RadRails for months now, so I have high hopes for the PHP tools as well. I’ll let you all know what I think. I’ve been using PDT inside Eclipse, so I’m curious how things will be different.

{ 0 comments }

WordPress 2.7 is greatness

by George on December 12, 2008

I just want to officially go on record as saying that the latest WordPress is sweet. A great big huge thank you to all the developers and testers that put this latest release together.

{ 2 comments }

Back to the grind

by George on November 24, 2008

After a bit of a break from the blog and a trip out of the country, we’re back at work and trying to get everything revved up again. It’s always hard for me to break away from my work world and unplug for a while. Working with the computer and writing code has been such a huge part of our lives for so long that it’s hard to imagine life without it. I’ve been writing code almost non-stop since my college years. It’s to the point that I often relate many other areas of my life to situations in software design. Since my wife is also a developer, we will use coding analogies to explain real-life situations to each other. We are a geeky couple I suppose; you should feel the most sympathy to our children though.

I really enjoyed the break, but it’s also great to be back in the swing of things.

{ 0 comments }

MAMP for PHP development on the Mac

by George on October 14, 2008

I’m a Mac guy. I haven’t always been a Mac guy but I was forced to make the change just over 2 years ago when I went to work for a local company that was exclusively Mac. After about a 2 to 3 month adjustment period, I began to see the light. Now I love the Mac OSX, I love my Macbook Pro, and I can not imagine buying a PC ever again. Especially after the Vista laptop headaches that have plagued our home for over a year now (but that’s another story). Of course I keep a couple of old XP machines around for testing purposes, and I can run XP on my Macbook Pro using Parallels. But for everything I do for fun and most of what I do for work is on the Mac.

I get to work on a number of PHP sites with the traditional LAMP setup (Linux, Apache, MySQL, and PHP). So when I got my Macbook Pro, I needed to get everything up and running so I could get busy on my development projects quickly. I’ve always built out my LAMP manually because I’ve never found a tool that could just take care of everything for me the way I want it set up. That is until I found MAMP. I downloaded it, hit the Start Servers button and BAM, I’ve got my web server, database, and PHP all running. I love that it’s totally isolated from everything else too. Everything is stored in the /Applications/MAMP/ directory. I also do Ruby and Java development on the same machine, and the isolation of MAMP makes it real easy to keep things from conflicting.

If you’re doing any PHP work on a Mac, I strongly recommend MAMP. It’s a great tool. A big thanks and hat tip go to the dev team responsible.

Next time I’ll tell you what I had to do to get the slow queries log working with MAMP. It was a bit different from what I’m used to.

{ 0 comments }

PHP to Ruby Rewrite :: Week Two

by George on September 20, 2008

Sadly, I was not able to spend nearly as much time on the rewrite project this week as I wanted to. I have a code release early next week for another project, and I still had a number of things to wrap up there. So, the rewrite project had to be put on hold for the second half of the week.

I did make some progress early in the week though. I now have 8 models working with all the relationships set up and behaving as expected. I decided to use a single-table inheritance pattern for a few of the models as well. This works really well. I debated the value of it early on. I really don’t like to see applications that seem to use complicated design patterns just for the sake of it. I’ve seen some extreme cases where it almost seemed like the developers were flipping through the Gang of Four Design Patterns Book making sure they used as many as they could. Early on it just seemed more practical to put some if blocks in various places to account for the different view behaviors I wanted to have, but in the end I realized that the single-table inheritance made the most sense.

[click to continue...]

{ 0 comments }

ActiveRecord does not like attributes called type

by George on September 15, 2008

Here’s an interesting issue that I ran into while setting up a bunch of new models for a new application. Ultimately I discovered that “type” is a reserved field name for classes that inherit from ActiveRecord.

When I tried to create a new object, one of the fields would not accept a value and remained nil. Here’s what I saw from the console.

>> a = Attachment.new(:name => "some name", :type => "Video")
=> #<Attachment id: nil, name: "some name", type: nil, file_name: nil, activity_id: nil, created_at: nil, updated_at: nil>

I was not seeing an error except from my rspec test which conveniently popped up since I’m running autotest.

ActiveRecord::RecordInvalid in 'Attachment should create a new instance given valid attributes'
Validation failed: Type can't be blank

I had a many-to-one relationship between two tables. In my design there is an Activity model which has many Attachments. An Attachment can be of various file types. For example it could be a PDF, image, video, etc. Since I felt there would be very little difference in behavior for the different types, I simply added a type field to the Attachments table so I could evaluate that for a few various display options. I knew about the single-table inheritance that is built into ActiveRecord, but it didn’t occur to me right away that this could be the cause of my problem. When I tried to start up Mongrel and insert a new Attachment through my browser, I got failures again, but of course this was because the persistence failed. Ahhh, I had the validates_presence_of :type in my Attachment model class which of course won’t allow persistence of a nill value to the database. So I was back to why it was nil in the first place. I removed validates_presence_of from the model and of course the record was persisted with a nil value for the type field. And still no errors. I checked the database and just as expected found the record with a NULL value for type.

Next I inserted a new row to the database manually with a type value. Then it comes. The moment when I get to slap my forehead and feel kinda silly. As soon as I hit the refresh on the browser to see the list of Attachments, I get the following error:

The single-table inheritance mechanism failed to locate the subclass: 'Video'.
This error is raised because the column 'type' is reserved for storing the class in case of inheritance.
Please rename this column if you didn't intend it to be used for storing the inheritance class or
overwrite Attachment.inheritance_column to use another column for that information.

This is a great error. It’s well worded, tells me what the problem is and how to fix it. I just wish this would have been thrown when trying to persist an object to data with an invalid type. But hey, now I get to add that as my own validation method.

I eventually decided to use single-table inheritance after all because there turns out to be more that just a few differences in how I need to treat these attachments.

{ 0 comments }

PHP to Ruby Rewrite :: Week One

by George on September 13, 2008

Well, we’re at the end of week one and I feel like we’ve made some decent progress on the big rewrite project. We spent some time going through the data design of the old application in order to get a lot of that back in our heads and sketched out on paper. We also spent some time learning a little more about Ruby and Rails in general, plus some specific things such as ActiveRecord. We also spent time installing and getting our environment set up like we want it. Finally, we started creating our Rails models.

The existing database was fairly well designed, but it does not use any kind of data modeling framework. I had created my own data access layer which essentially amounts to a set of function libraries for every type of data access and manipulation needed. These functions go beyond simple data access though; quite a bit of business logic (and even *gasp* some view logic) has crept in over time. When faced with restrictions from the CMS I was working in, it was just too easy to hack out something that would work. Because to fix things the right way meant, well, a big rewrite. So we decided to make a few modifications to the database design to make it  fit better with Rails ActiveRecord style development. On paper, our new design has 21 models so far.

It’s now the end of the week. We’ve learned a lot. (Like Matz said at the Lone Star Ruby Conf last weekend, the best way to learn is just to get in there and start working with it.) Our environments are (mostly) set up like we need. We’ve designed out our data models on paper. It was important to me to follow a BDD process using rspec and autotest from the beginning, so we’ve got those things set up and working as well. We created a Rails app, decided we needed to change a few things, scrapped it and started again. We have half a dozen models in the newest attempt and (almost) have those all talking to each other how they need to. I can’t wait to see how far we can get next week.

{ 0 comments }