exceptionz

Thoughts on Technology, Methodology and Programming.

Archive for the ‘Ruby’ Category

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 »

scrAPI on Snow Leopard

Posted by Marcus Wyatt on 3 November 2009

Today I needed to scrape some data from a website and tried to use the trusted old scrAPI to do the job. Grrrr, its not working. Throwing an error:

Scraper::Reader::HTMLParseError: Scraper::Reader::HTMLParseError: Unable to load /Library/Ruby/Gems/1.8/gems/scrapi-1.2.0/lib/scraper/../tidy/libtidy.dylib

After some time on google I didn’t find any fixes for the issue. So I decided to build from source…

I grabbed the assaf’s github repository.

  • git clone git://github.com/assaf/scrapi.git

Then tried the tests by running

rake test

117 tests, 346 assertions, 0 failures, 44 errors

Nope errors all over the show… Looking at the original exception message, I checked if the libtidy.dylib exist on the lib/tidy directory. Nope, not there….

So where do I get this library file….

MacPorts to the rescue… Install tidy from MacPorts using the following command:

  • sudo port install tidy

Now we need to find where MacPorts installed the files using the following port command:

  • port contents tidy

The result:

Port tidy contains:
/opt/local/bin/tab2space
/opt/local/bin/tidy
/opt/local/include/buffio.h
/opt/local/include/fileio.h
/opt/local/include/platform.h
/opt/local/include/tidy.h
/opt/local/include/tidyenum.h
/opt/local/lib/libtidy-0.99.0.dylib
/opt/local/lib/libtidy.0.dylib
/opt/local/lib/libtidy.a
/opt/local/lib/libtidy.dylib
/opt/local/lib/libtidy.la

Now all we need to do is copy the library file to our scrAPI source directory:

  • cp /opt/local/lib/libtidy.dylib [your source location]/lib/tidy/libtidy.dylib

Ok, before we speed ahead. Lets just run those test to check if all is fine:

117 tests, 474 assertions, 0 failures, 0 errors

Awesome, we are almost there. Next we need to build the gem using the rake:

  • rake package

Make sure you get a ‘Successfully built RubyGem’ message. Now we are ready to install the newly build gem and test scrAPI again.

  • sudo gem install pkg/scrapi-1.2.1.gem

And there you go, scrAPI working again.


Posted in OS X, Ruby, RubyGems | 5 Comments »

Run gem install behind a firewall in Windows

Posted by Marcus Wyatt on 18 March 2008

I’m contracting at a client running a Novell network and wanted to create some small little ruby scripts to automate some tasks for me. But I ran into problems using gem install behind their firewall. I’m getting the following error:

ERROR: While executing gem … (Gem::RemoteSourceException) HTTP Response 407

Here is the steps I followed to get gem install working on my windows xp machine in painstaking detail: 🙂

Firstly we need to set the HTTP_PROXY environment variable. I’ve played around with different options, using uid and pwd and other suggestions, but all I needed was the following:

  1. On the desktop right click the ‘My Computer’ icon and select properties.
  2. Now you can either add the HTTP_PROXY variable to the ‘User’ or the ‘System’ variables by clicking the ‘New’ button.
  3. Within the new system variable dialog, specify ’HTTP_PROXY’ as the variable name and in the value area a url in the following format – http://%5Bproxy_ip%5D:%5Bproxy_port%5D – i.e. http://127.168.1.3:5865

Next we install the Ruby Win32 SSPI which gives ruby the ability to authenticate with ISA natively. We need this library because as far as I understand, it patches the Open-uri library because of some incompatibilities with windows. Anyways, follow the following steps to get it working:

  1. Download rubysspi from the Ruby Win32 SSPI project page(also available as gem install rubysspi but that doesn’t help much, does it?)
  2. Install the gem locally using the following command: gem install [local_path_to_gem]\rubysspi-1.2.3.gem i.e. C:\gems\rubysspi-1.2.3.gem
  3. Now copy the spa.rb file from the gem install directory and paste it in the site-ruby directory. i.e. If ruby is installed in C:\ruby, then the paths should be:
    • origin path – C:\ruby\lib\ruby\gems\1.8\gems\rubysspi-1.2.3\spa.rb
    • destination path – C:\ruby\lib\ruby\site_ruby\spa.rb
  4. Find gem.bat in your ruby bin directory (C:\ruby\bin) and replace the last line (i.e. "%~d0%~p0ruby" -x "%~f0" %*) with the following line – @"ruby" -rspa "c:\ruby\bin\gem" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. Test you can access the remote ruby gems by executing the following command: gem list rails -r
  6. You should see similar output as shown above.

Now we can work again without any issues when trying to install or update gems.

Enjoy!!!

Technorati Tags: , ,

Posted in Development, Rails, Ruby, Software, Tools, XP | 36 Comments »

TextMate command to annotate your current ActiveRecord Model with the DB Schema

Posted by Marcus Wyatt on 18 March 2008

Edit: If you can’t wait until the end, here is the download link.

Who hasn’t used the Annotate Models plugin written by Dave Thomas, of Rails Pragmatic Studio fame? If you haven’t don’t fret… The plugin basically adds a comment block to the top of all of your model classes documenting the current database schema for the given model. I like to have the info in my model files to make it a little easier to work with models.

Annotated Models Plugin

The rails bundle within TextMate gives you a ‘Show DB Schema for current class’ command you can press to show a tool tip with the database schema (Control + Shift + Command + S). This works great, but I find the command sequence to long and the slight wait to see the schema info breaks my rhythm.

Show DB Schema for Current Class

To solve the problem I made a copy of the source files used by the command and modified it slightly to output the info as comments at the top of the file. Now I have nicely annotated model files. This is a real time saver.

Annotated Models Bundles

The bundle also contain the the Beautify command. This command adds automatic code formatting capability for your ruby code. I found the beautify command from Tim Burks. Cheers Tim…

You can download the bundle here.

Technorati Tags: , , , ,

Blogged from TextMate

Posted in Mac, OS X, Rails, Ruby, Software, TextMate | Leave a Comment »

Ruby, Rails, TextMate, JavaScript, Mac OSX, Subversion

Posted by Marcus Wyatt on 15 February 2008

Ruby

Rails

TextMate

JavaScript

Mac OSX

Subversion

Technorati Tags: , , , , ,

Posted in JavaScript, Mac, OS X, Rails, Ruby, Software, Subversion, TextMate | Leave a Comment »

Ruby, Rails, RSpec, JavaScript, Ubuntu, Mac OS X

Posted by Marcus Wyatt on 12 February 2008

Ruby

Rails

RSpec

JavaScript

Ubuntu

Mac OS X

Technorati Tags: , , , , ,

Powered by ScribeFire.

Posted in BDD, JavaScript, Mac, OS X, Rails, RSpec, Ruby, Ubuntu | 1 Comment »

Ruby, Rails, RSpec, Rails Plugin, JavaScript, OS X

Posted by Marcus Wyatt on 29 January 2008

Ruby

Rails

RSpec

Rails Plugin

JavaScript

OS X

Technorati Tags: , , , , ,

Post created with TextMate.

Posted in JavaScript, OS X, Rails, Rails Plugins, RSpec, Ruby | Leave a Comment »

Ruby, Rails, Rails Plugin, CSS

Posted by Marcus Wyatt on 20 January 2008

Ruby

Rails

Rails Plugin

  • AttributeFu – makes multi-model forms so easy you’ll be telling all of your friends about it.
  • assert_efficient_sql – the assertion intercepts and copies out your MySQL SELECT statements, then calls EXPLAIN on each one, and inspects the results for common problems.

CSS

SEO

Technorati Tags: , , , ,

Post created with TextMate.

Posted in CSS, Rails, Rails Plugins, Ruby, SEO | Leave a Comment »

Ruby, Rails, OS X (Leopard), CSS

Posted by Marcus Wyatt on 14 January 2008

Ruby

  • Hash#tomod – extend your class to except a hash of values in the constructor and then access the values as if they are read accessors on the object. Very enlightening post, I’m sure ActiveRecord::Base implements something.

Rails

OS X (Leopard)

CSS

Technorati Tags:

,

,

,

Powered by ScribeFire.


Posted in CSS, Mac, OS X, Rails, Ruby | Leave a Comment »

Ruby, Rails, JavaScript

Posted by Marcus Wyatt on 8 January 2008

Ruby

Rails

JavaScript

Technorati Tags: , ,

Post created with TextMate.

Posted in JavaScript, Rails, Ruby | 1 Comment »