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
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
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
Posted by Mike Blake
Sat, 15 Jul 2006 10:30:00 GMT
Declare new Classes Inside Modules to Avoid Conflicts
In the ruby language you cannot have a Module with the same name as a Class. The reason is that in any instance of the ruby interpreter, all root level accessible Objects are stored in a Hash of constants as either Modules or Classes. This can get cluttered pretty quickly in a large application. Try throwing the line 'p Module.constants' in the middle of a medium sized Rails application.
However, if a class is part of a Module, which acts as a namespace in ruby, it’s name never makes it to Module.constants. So it can have the same name as an existing Module.
To see a demonstration of this, I executed the following ruby code.
module One
end
class Two
def self.to_s
"2"
end
end
p Two
class One::Two
def self.to_s
"1::2"
end
end
p One::Two
class One::Three
def self.to_s
"1::3"
end
end
p One::Three
p Module.constants
class One::One
def self.to_s
"1::1"
end
end
p One::One
class One
def self.to_s
"1"
end
end
p One
Here’s what happened. (output below). A Module named One was created and so was a class named Two. And the interpreter saw that it was good. Then, in the One module, classes One, Two, and Three were created. And the interpreter saw that it was good.
Then I took a peek at Module.constants. The One Module, and the Two Class were saved as constants. But the Three Class was not stored as a constant because it is not at the root level. Since Classes created within Modules are not stored as constants,I was allowed to create a One Class inside the One Module without a getting a TypeError.
But all is not well in paradise. When the program tried to create a class named One it got the error
-:35: One is not a class (TypeError)
That’s because it’s already stored in constants as a Module.
As Ruby grows in popularity, this could become a problem. Especially in the Rails framework where all Model objects are at the root level. Considering this, it’s a good habit to use modules as namespaces when creating new classes in things like plugins and gems to avoid a TypeError.
Output:
1::2
1::3
2
["TrueClass", "FloatDomainError", "Fixnum", "TOPLEVEL_BINDING", "SignalException", "String", "SystemCallError", "UnboundMethod", "Buffering", "Rational", "ThreadGroup", "CROSS_COMPILING", "ScriptError", "MatchData", "Thread", "IndexError", "STDOUT", "One", "SecurityError", "Integer", "SingleForwardable", "Config", "RELEASE_DATE", "Exception", "NoMethodError", "Proc", "GC", "TypeError", "Binding", "Signal", "FALSE", "RUBY_PLATFORM", "Forwardable", "Bignum", "SystemExit", "Date", "NotImplementedError", "EOFError", "FileTest", "TRUE", "Numeric", "Interrupt", "ARGF", "Array", "SyntaxError", "MatchingData", "RUBY_VERSION", "ParseDate", "Time", "RangeError", "ENV", "NIL", "Enumerable", "Module", "PLATFORM", "STDERR","Two", "NoMemoryError", "Float", "Regexp", "DateTime", "Data", "ZeroDivisionError", "ARGV", "Dir", "Process", "Range", "ThreadError", "ArgumentError", "Object", "IO", "Comparable", "LocalJumpError", "Math", "Marshal", "RuntimeError", "STDIN", "Method", "VERSION", "RegexpError", "Hash", "Precision", "Kernel", "Continuation", "File", "SystemStackError", "OpenSSL", "FalseClass", "Errno", "NilClass", "StandardError", "LoadError", "ObjectSpace", "RUBY_RELEASE_DATE", "Gem", "IOError", "Symbol", "Struct", "NameError", "Class"]
1::1
-:35: One is not a class (TypeError)
Posted in Create | Tags constants, module, namespace conflicts, ruby | 1 comment
Posted by Mike Blake
Fri, 23 Jun 2006 12:16:00 GMT
I’m registered now at Rails Conference. The first day was awesome, though I got in late. I forgot what a great speaker Dave Thomas is.
Someone during the install fest commented that they didn’t like the way layouts are in a separate directory under views in a default Rails application. Dave said that he questions little things like that in the framework. But made the following suggestion. Just go with the flow. Because if you don’t use the defaults, one day 2 years from now, another Rails developer will open up that app, and say “Where the hell are the layouts?”
Dave’s response really captured what’s going on here. The Rails team has created an awesome framework that has so simplified development of a web application so that we can all focus on more important things. It’s like when you first start out on a development team, everyone agrees on certain standards that simplify comunication. It doesn’t really matter exactly what these are, everyone is now on the same page, and you function better as a team.
The Rails guys, by releasing the framework as open source, have in effect included us all on one big team. Mike Clark commented what a great community this is and it’s true. At install fest, people were all just helping each other out, regardless of experience or noteriety. It’s going to be a great conference.
And if you haven’t stared learning Ruby or Rails, it’s time. I’ve noticed a huge spike in the number of ruby and rails jobs on dice and monster in the last few weeks. And rails projects are keeping my own dance card full.
So come on, go with the flow!
Posted in Create | Tags Dave Thomas, go with the flow, Mike Clark, rails, rails conference, ruby | no comments