Rails plugins I love

One thing that amazes me about Rails is that there are many plugins out there for all kinds of features and functionality. From large user authentication schemes (acts_as_authenticated), to smaller simple widget type things, you can almost always find the functionality you are looking for by searching a plugins repository.  Here are a few of the great plugins I’ve used in my apps recently:

File Column Plugin: Great for uploading photos into a column of a database table object.  Paired with RMagick, it’s easy to create different sized images (thumbnail vs. original), with just one upload.
acts_as_ratable: Netflix model starred rating system.  It’s AJAX based, so super slick.  You can also swap out the images, so you don’t have to use stars.
calendar date select: A simple calendar picker, with three built in options for look and feel … just swap out the css!


Acts as Upgradable? “Gotchas” in Rails 2.0.2

Just did the Rails upgrade to 2.0.2.  Lots of new stuff … which is great, but there is no concept of backwards compatibility!  After the upgrade, my app was  immediately hosed!  Some key changes that were made to session management were part of my problems, since I am using the acts_as_authenticated plugin.  In my app’s controller,  the line "observer :user_observer", was no longer recognized as a valid line of code.  Instead, this has been moved to the environments.rb file.  To get past this problem, simply add this line of code to your Initializer.run function, and remove the offending line from your controller.

config.active_record.observers = :user_observer

The second major problem I hit looked like this:

! FAILSAFE /!  Mon Jan 21 13:39:53 -0500 2008 Status: 500 Internal Server Error A secret is required to generate an integrity hash for cookie session data. Use config.action_controller.session = { :session_key => "_myapp_session", :secret  => "some secret phrase of at least 30 characters" } in config/environment.rb

An easy fix, since the error told you exactly what to do.  I put this line of code into my environments.rb file, right above the last fix:

config.action_controller.session = { :session_key => "_session", :secret => "some secret phrase of at least 30 characters" }

The last error I hit, had to do with the "scaffolding" I had set up.  I thought scaffolding was a brilliant thing, providing a safety net, for all those simple functions, that you don’t need to be unique per app.  Basically, if you put scaffold :object at the top of your controller, it generates code for things like "new", "update", "create", "list", and "edit".  It was so easy popping this one line into the controller.  But with Rails 2.0.2 you see this error: 

undefined method `scaffold’ for Controller:Class

Scaffolding in Rails 2.0 is now generated with a script.  ./script/generate scaffold ModelName field1:type field2:type field3:type

Why not let us keep the old way too?  Again, backwards compatibility does not seem to be the priority with this "cutting edge" platform.

The other thing you need to do after the upgrade, in the environments.rb file, is change the definition of RAILS_GEM_VERSION like this:

RAILS_GEM_VERSION = ‘2.0.2’ unless defined? RAILS_GEM_VERSION

After applying those adjustments, my app was back up and running.