Category: Programming

Project Railsway – a TV Series idea

Posted by – December 11, 2007

Tonight I was watching “Project Runaway” which is a television series that collects 12 aspiring clothing designers to compete in a series of challenges and the top 3 finalists get to show their collection of designs in front of fashion industry professionals at a fashion week event. Each challenge has a time limit and some are as short as 10 hours, some go to 18 hours or more.

For some reason I find the show rather interesting to watch, I find it motivating to watch people with such obvious passion for their work and they are challenged to put all their skill and creativity into each challenge or risk not moving onto the next round.

There is another industry that I know of where many of the people in it are highly passionate, and that is Ruby on Rails web developers. I think it would be entirely possible to do a show with a similar format to “Project Runaway” and pull it off.

I know, who wants to see programmers sitting in front of computers with lines of code on their monitor, how is that entertainment? However, in “Project Runaway” they seldom show the actual details of making the clothing. There are a lot of other things happening, most of the show is comprised of showing the background story, the interactions of the contenders with each other, interviewing them before the challenge, during the challenge, before judging, during judging, after judging, plus the judges and their responses, showing the clothing at various stages of being made, from collecting the fabric, stressing out during the alloted time, fitting the clothing to the models, getting advice from the group’s mentor and then the model walkout. There is a lot involved to the television show without boring the viewers with the tedious details of the actual sewing and other design work.

Because of that, I think that a Ruby on Rails design show would work very well. Prototypes of the websites can be shown in the varying stages from the begining to finish. Also, Ruby on Rails developers can build working webapps in as little as 10 hours.

An added bonus is that there is quite a few Ruby on Rails developers that are photogenic. Quite a few are the stereotypical artsy funky stylishly dressed mac users. Not as many Ruby on Rails developers are fat or sloppy as you would expect.

Validates_uniqueness_of and single table inheritance

Posted by – May 18, 2007

If you’re using STI (single table inheritance) with some Ruby on Rails models, and you need to make sure some fields are unique across all the models, you can use validates_uniqueness_of in the parent model using the :scope option to apply it to all the models. So in this instance since you have a type field in the table, you would use:


validates_uniqueness_of :name, :scope => :type

However, you might encounter trouble with type being a deprecated method that is aliased to class. The fix is to add this before the validation:


undef_method :type

Making Rake tasks ignore Rails observers

Posted by – May 16, 2007

Have you ever run “rake db:migrate” on an empty database (or you did “rake db:migrate VERSION=0″ to empty the database). And then it fails on you like this?


rake db:migrate
(in /Users/foucist/rails/myproject)
rake aborted!
Mysql::Error: #42S02Table 'myproject_development.users' doesn't exist: SHOW FIELDS FROM users
(See full trace by running task with --trace)

Invariably, rake failures are caused by something in the environment file that is expecting something in the database. Sometimes people stick a .find() in the environment file unfortunately. In this case, it turned out to be the user observer.


Rails::Initializer.run do |config|
config.action_controller.session_store = :active_record_store
config.active_record.observers = :user_observer
end

After examining the code for the rake tasks in /opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/tasks/ I noticed that the environment file was loaded with ‘require’. That means that environment.rb is code (obviously) and now I can change the line for the user observer to not load when rake is loading it.


config.active_record.observers = :user_observer unless File.basename( $0 ) == "rake"

Viola. File.basename is just a trick to parse the $0 variable which is the name of the binary thats loading the file.