Thoughts on Technology, Methodology and Programming.

Archive for February, 2010

Gems, gems, and more gems…

Posted by Marcus Wyatt on 20 February 2010

I’ve been working frantically at gemifying some plugins. I can’t unfortunately lay claim to have written these gems, but I needed to use them as gems with the new bundler system. So I created or forked the projects on github and used jeweler to gemify them

  • pgexplain – The Rails gem shows the output, in your application logs, of applying “Explain” or “Explain Analyze” to the select queries of your rails application using PostgreSQL.
  • railsonpg – This is timesaver for middle/large Rails application which use PostgreSQL as database. Create/drop Views, Functions, Triggers, Foreign keys in your migrations using ruby syntax.
  • swffu – swffu (pronounced “swif-fu”, bonus joke for french speakers) uses SWFObject 2.2 to embed swf objects in HTML and supports all its options. SWFObject 2 is such a nice library that Adobe now uses it as the official way to embed swf! SWFObject’s project can be found at http://code.google.com/p/swfobject swffu has been tested with rails v2.0 up to v3.0b and has decent test coverage so rake test:plugins should reveal any incompatibility. Comments and pull requests welcome: http://github.com/marcandre/swffu

The swffu plugin to gem conversion was the most work. Since the plugin used install.rb and uninstall.rb to add/remove some assets (javascripts, etc) to the rails application structure. I had to rethink how this functionality would be achieved. I decided to use rake tasks to accomplish the same functionality. The only trick is to add the require ‘swffu/tasks’ to the Rakefile.

So enjoy these new gems!

Posted in Uncategorized | Tagged: , , | Leave a Comment »

How to fix the iconv require error in Ruby 1.9

Posted by Marcus Wyatt on 3 February 2010

So you’re trying out the pre-release version of Rails 3.0 with Ruby 1.9 and you keep on getting the following error:

activesupport-3.0.pre/lib/active_support/inflector/transliterate.rb:2:in `require’: no such file to load – iconv (LoadError)

If you are using rvm to install and switch between different versions of ruby then follow the following steps:

  1. Install readline using rvm: rvm install readline rvm package install readline
  2. Now install iconv by executing: rvm install iconv rvm package install iconv
  3. if you already have a version of Ruby 1.9 installed, we need to remove it by executing: rvm remove 1.9.1/1.9.2
  4. The final step is to re-install the version of ruby: rvm install –trace 1.9.2 -C –with-iconv-dir=$HOME/.rvm/us
    (If you are having problems with the command, use the pastie that Glenn Rempe posted in the comments. Thanks Glenn)

Now to test that it worked:

  1. Change to the ruby version you installed: rvm use 1.9.1/1.9.2
  2. Check you are on the right version of ruby: ruby -v #=> ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.2.0]
  3. Start a new irb session
  4. Now you should be able to require ‘iconv’ and get a ‘true’ result

    irb(main):001:0> require ‘iconv’

Now you should be good to go!

Posted in Rails, Ruby | Tagged: , , | 9 Comments »