Tuesday, February 16, 2010

Several times in the last year I have wished that a gem could have rake tasks that would be loaded into a Rails app. I looked into it several times but kept running into dead ends with Rails 2. Since the Rails 3 beta came out I decided to try again, this time with much more success.

Basically you are trying to include a rake task in your rails app, the tricky part is you are trying to include the rake task from the gem it is inside of, which itself is being included in the rails app.

In this file we create a railtie class inside of our module, our new class has to be a descendant of the Rails::Railtie class. The 'rake_tasks' method is defined in the Rails::Railtie class, it takes a block that it then runs during the initialization of the rake environment in your app.

Sunday, February 7, 2010

Initial application creationInitial application creation is as easy as it has always been. The output is formatted a little better and you can create an app with a path instead of just a subdirectory name. A .gitignore file is created automatically as well as a few .gitkeep files on directories that don't start out with files in them, a really nice touch for those of us who use git.

script/* replaced by script/rails
This takes a little getting used to if you are used to the old script commands. Stuff like "script/console" doesn't work any more, it has been replaced by "rails console" or "rails c" if you prefer the shorthand version. "rails --help" will be your friend until you get used to the new commands.

Generators
The new generator system seems to be very well thought out and has all kinds of great new features if you want to modify templates or write your own generators. Even if you are just running the default generators things have improved a bit. The default templates have improved, for example div tags instead of p tags and use of a form partial instead of duplicating code in the edit and new views.

Testing
Testing out of the box does not seem to have changed much. The main thing I noticed is that most of the major testing tools are not yet working with the rails 3 beta. I tried out shoulda, rspec, and cucumber all without success.