Posted by Mike Blake
Tue, 22 May 2007 21:16:00 GMT
Something fantastic is happening in the Ruby and Rails World.

Do unto others
Open source developers know from experience that what goes around comes around. Contributions to projects like Rails invariably come back to benefit everyone, including the contributor. The community is now thinking on a larger scale. Frameworks come and go, but love is timeless .
The Summer of Love
Whytheluckystiff is focusing his power on Hackety Hack an amazing application that teaches children programming. And it’s likely more zeitgeist than coincidence that a professor from MIT, where the generous open source license originated, has started the noble project called One Laptop per Child . Developers everywhere like Amy Hoy are giving back in order to share the passion.

Chad Fowler has challenged the entire community to harness our newfound passion to do great things. And the community has only just begun to respond. During RailsConf over $33,000 was raised for charity.
Software evolves rapidly. Humanity seems to evolve at a slower pace, but if you watch carefully, with ruby colored glasses , you can see it happening.
Posted in Create, Pray | Tags love, rails, ruby | no comments
Posted by Mike Blake
Thu, 26 Apr 2007 11:30:00 GMT
Update 4/30
I finally did find the real Hibernate 3 Migration Guide. My fun with Hibernate is over though, I've found an easier persistence solution with the clients homegrown method. I believe every single java project I've worked on in the past 10 years has used a different and unique Persistence mechanism. My favorite was Francois' PersistentEntity at ViaFone.
I’ve been strugling for the last day trying to get a Java application working, mainly, trying to get Hibernate to see a DataSource. Now I’m at a point where I get this error message:
[junit] (cfg.Configuration 1312) configuring from resource: /hibernate.cfg.xml
[junit] (cfg.Configuration 1289) Configuration resource: /hibernate.cfg.xml
[junit] (util.DTDEntityResolver 30 ) Don’t use old DTDs, read the Hibernate 3.x Migration Guide!
A quick search does not turn up a Hibernate Migration Guide, so I decided to create this one.
The Hibernate 3.x Migration Guide
Get Ruby
Install Rails
Rebuild your application.
Have fun again!
Posted in Create | Tags hibernate, migration, rails, ruby | no comments | no trackbacks
Posted by Mike Blake
Sat, 31 Mar 2007 13:11:00 GMT
Rails developers working on enterprise software projects are suprised to discover the lack of automated tests in many mature web applications. As frustrating as this can be, A lack of automated tests is also a tremendous opportunity to
- Learn your non-rails applications underlying database structure.
- Demonstrate to a devlopment team the power of The Rails Framework.
- Encourage automated testing.
Rails may be the quickest path to automate some basic test of your non-rails applications data model. These steps will get you all set up to write your automated tests in Ruby.
- Connect to Your Enterprise Database
- Set DB Conventions
- Safety Net
- Duplicate the Schema
- Extract Development Data
I. Connect to Your Enterprise Database from Rails.
Download and install any os driver, ruby gems, and rails adapters needed to connect to your database:
Supported Rails Databases:
MySQL
DB2
Oracle
Sybase
SQLServer
PostgreSQL
Firebird
II. Set Your Existing Database Conventions
Rails Recipes
, Recipie #16 can walk you through this very quickly.
Identify any conventions used by your legacy database. Application wide conventions can be set in the config/environment.rb file.
They are specified by calling the appropriate class methods available on ActiveRecord::Base. The methods you need to call depend on how your database is configured:
ActiveRecord::Base.table_name_prefix 'myapp_'
ActiveRecord::Base.table_name_suffix = '_def'
ActiveRecord::Base.sequence_name = 'dev_company'
ActiveRecord::Base.pluralize_table_names = false
ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore # or :table_name
III. Safety Net
Load the SafetyNet Plugin into your rails app to prevent from destroying your development database.
IV. Duplicate Your Database Schema
OK , with your dev and test development databases set correctly, let’s try duplicting the schema.
rake db:test:clone
If this works right off the bat, you’re one of the lucky ones. Skip to Extracting Development Data
If you recieved errors from the clone command, do steps A through C .
A. You can now correct any errors you may have had by manually modifying schema.rb . See Oracle Errors for some problems I had with the Oracle Database. Since schema.rb is generated, it’s a good idea to rename it when you modify it manually.
B. The clone command above may have started loading data; you need may to purge the test db.
rake db:test:purge
C. Tell rake to load your new schema file by passing the new name, relative to RAILS_ROOT in the SCHEMA environment variable:
rake db:schema:load RAILS_ENV=test SCHEMA=db/oracle_schema.rb
Copy the code from
Rails Recipe #42: extract_fixtures.rake to your RAILS_ROOT/lib/tasks directory.
TIP: If your develoment database has lots of data, Modify the SQL Select in this code to limit the amount of data you copy using the SQL limit statement:
sql = "SELECT * FROM %s limit = 100"
Or for a proprietary database, the equivalent command:
sql = "SELECT * FROM %s WHERE ROWNUM<=100"
Then run
rake extract_fixtures
You’ve made your testbed so you can lie in it.
You now have and exact copy of your development database, and a collection of sample data in Yaml format, and are ready to begin writing some Unit Tests. Stay tuned for some examples. Rail on!
Posted in Create | Tags database, rails, rake, ruby, unit tests, yml | no comments
Posted by Mike Blake
Thu, 29 Mar 2007 21:15:00 GMT
When rails on jruby and connecting to Oracle via JDBC ,the following error eventually appears:
Update:
java.sql.SQLException: Io exception: Broken pipe
Fix:
You need a dedicated connection from Oracle. Change the url: line in database.yml from
url: jdbc:oracle:thin:@localhost:1521:XE
to
url: jdbc:oracle:thin:@(DESCRIPTION = (ADDRESSLIST = (ADDRESS =(PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))) (CONNECTDATA =(SERVER = DEDICATED) (SID = XE)))
Workarounds
Duplicating an existing Oracle Database using the build in task rake db:test:clone presented a few problems. Here’s what I did to work around them.
ORA-01727: numeric precision specifier is out of range
OCIError: ORA-01727: numeric precision specifier is out of range (1 to 38): CREATE TABLE employee (id NUMBER(38) NOT NULL PRIMARY KEY, createddate DATE DEFAULT NULL, startdate DATE DEFAULT NULL, jobid DECIMAL DEFAULT NULL, totalhours NUMBER(126) DEFAULT NULL)
Fix:
For some reason whne rails dumps the schema, it reports Oracle type FLOAT as NUMBER(126), so you just need to changed that back to FLOAT if you want to import that schema.
OCIError: ORA-00972 identifier is too long:
OCIError: ORA-00972: identifier is too long: CREATE SEQUENCE gametime_responsibility_ref_seq START WITH 10000
Fix:
Rails tries to create sequences in Oracle to handle AUTOINCREMENT id fields. It uses TABLENAME = ’SEQ’ for the sequence name. If a sqequence name is too long then you have to shorten it in schema.rb .
OCIError: ORA-00907: missing right parenthesis
OCIError: ORA-00907: missing right parenthesis: CREATE TABLE board (id NUMBER(38) NOT NULL PRIMARY KEY, name VARCHAR2(150) NOT NULL, name VARCHAR2(150) NOT NULL, parent VARCHAR2(150) DEFAULT NULL, loglevel DECIMAL DEFAULT NULL, modifieddate DATE(6) DEFAULT NULL, token DECIMAL DEFAULT NULL)
Fix:
For some reason Rails assigns Date fields a size in schema.rb . You’ll need to change all occurances of DATE(6) to DATE .
Posted in Create | Tags oracle, rails, rb, schema | 1 comment
Posted by Mike Blake
Mon, 19 Feb 2007 18:23:00 GMT
The assert_select method for testing views was added in Rails 1.2, so the first thing to check if you’re getting the error below is that you’ve upgraded to 1.2
> 2) Error:
>test_expire_old_ads(AdExpirationTest):
>NoMethodError: undefined method `assert_select' for #
> c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/test_process.rb:432:in `method_missing'
Now I upgraded to 1.2 and still kept getting the above error. The problem was that my application was set to use Rails 1.1.6 in the config/environment.rb file:
RAILS_GEM_VERSION = '1.1.6'
So the solution is to comment out that line, or alternatively ,set it to the latest version. Also make sure you’re not frozen to a specific Rails version in the vendor directory.
Posted in Create | Tags assert_select, NoMethodError, rails, testing | no comments
Posted by Mike Blake
Wed, 14 Feb 2007 21:07:00 GMT
ORUG
At this months Orlando Ruby User’s Group meeting, I did my Testing on Rails presentation. In it I touched on just some of the benefits of having an automated suite of Unit, Functional, and Integration tests.

Later I thought of another major benefit. Tests help other people on the project, in addition to the author of the test.
Good Habits are Contagious
Recently I had the opportunity to work on a project with Harris Reynolds. Harris did something very important that sadly, you don’t see on every Rails Project. He wrote a unit test. Lot’s of us wrote tests , but this particular test stood out for two reasons. The first was when it was written.
Writing Tests First
Harris had found a bug in a model object that I had created. To notify me, he checked in an assertion that failed, then emailed me. This saved me time searching thought and remembering code I had written. I simply typed rake test:recent which runs all recently changed tests in a Rails application . The error took me right to the problem, and I immediately fixed the bug.
Testing a Deployment
The second reason I remember this test happened at least a month later. The application was being deployed to a new machine, and the test failed. The particular model object being tested pointed to a different database that the rest of the application, and it turned out that that database hadn’t been installed correctly on the new machine. Harris’s test told the problem straight away, and saved time once again.
Unit Testing: the gift that keeps on giving.
Thanks Harris!
Posted in Create | Tags ORUG, rails, ruby, unit tests | no comments
Posted by Mike Blake
Wed, 07 Feb 2007 21:14:00 GMT
Curent Mood: Bored with Deleting the Production Database
I thought I was the only clown working on Rails projects and ignoring the warning in config/database.yml and using rake to wipe out perfectly good databases. But I’ve seen it happen to others now, and enough’s enough. So I created the
SafetyNet Plugin
.
You can install Safety Net in your app, by running
ruby script/plugin install svn://rubyforge.org/var/svn/apptrain/trunk/vendor/plugins/safety_net
That’s it. Now, If the test database points to the same database as development or production running rake will display the following message:

rake aborted!
The name of your test database matches production or development.
How it Works
Purging the poor innocent database is prevented in two ways.
- By adding a prerequisite check to the rake script that normaly performs this task.
- By modifying the fixtures method on ActiveRecord to avoid the same fate when running individual tests with the ruby command.
Posted in Create | Tags apptrain, plugin, rails, rails test database, rake, safetynet, safetynet | 1 comment
Posted by Mike Blake
Wed, 31 Jan 2007 16:25:00 GMT
As you develop a nice well organized Rails application, you’re sure to utilize some of the great open source code already written by Rails developers.
A common practice is to install a plugin or some other code into your application, then add that code to subversion. Some problems with this are that a checkout of your app now takes longer, and if the plugin improves, you are using old code in your application. A neater solution is to access third party code using SVN Externals.
Using Tortoise SVN, right click inside the vendor directory of your app, then choose ‘properties’ from the menu.

Click the ‘Subversion’ Tab with the little turtle. Then choose svn:externals from the dropdown in the middle of the screen.

Now in the text area, enter the plugin you want to include.
acts_as_authenticated http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated
The format here is important, the first word the entry, before the first space will be the directory name where the code will live. After the first space is the url for the repository. Click ‘OK to save the external. Then go up one directory and do a checkout of the ‘vendor’ directory.
Now:
- If the plugin code changes, you’ll receive the new code whenever you do an Update.
- Additional coders who check out the repository have the option to ‘Omit externals’ if they don’t need the portion of the code you’ve included.
- There’s a clear distinction in your repository between the code you’re maintaining, and third party code.
Posted in Create | Tags externals, rails, subversion, svn, tortoise | no comments
Posted by Mike Blake
Thu, 21 Sep 2006 17:25:00 GMT
The folks at FanNation have done something that no one else in the sports world has done.
They’ve created a comprehensive site for sports fans to gather and share information about their favorite teams and players (fantasy too) , and it’s all free.
I spent some time with the developers at FanNation working on the map on the home page. They are a sharp bunch, and I’m constantly amazed at the features they are adding each time I visit. Fannation is now one of the biggest websites around developed on Ruby on Rails. Tag clouds, in place edits, Dynamic news updates using AJAX calls, personalized blogging. This site is a tremendous example of practical usage of some of the latest technologies. And it’s loads of fun.
There’s tons of other functionality I haven’t explored yet, but definitely keep an eye on FanNation!
Posted in Create | Tags fannation, rails, ruby | 1 comment
Posted by Mike Blake
Tue, 12 Sep 2006 14:30:00 GMT
If you’re a programmer like me you’re a little intimidated by the Hackfest. That is , you’ve had several programming gigs over the years, attended a few more day long meetings than you’d have liked, and fear that you’ll be embarrassed by your perceived lack of skill compared to the young whiz kids with a burning passion for creating software.
We’ll let me assure you, the spirit of the hackfest is one of learning and cooperation and not at all that of oneupmanship or competition. At least not at the ORUG .
I had a blast this past weekend and learned a lot from my piers, and left with the feeling that I had helped out as well.
So my advice, fear not and attend a Hackfest!
Posted in Create | Tags hackfest, ORUG, rails, ruby | 1 comment