Merb 1.0 Install Error:
merb-core requires RubyGems version >= 1.3.0

Written by Ben

When I tried to gem install Merb 1.0 I got this error

ERROR:  Error installing merb:
  merb-core requires RubyGems version >= 1.3.0

I tried to do a gem system update to the newest version of RubyGems (1.3.1) which failed.

$ sudo gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.1
ERROR:  While executing gem ... (NameError)
    undefined local variable or method `remote_gemspecs' for #<Gem::Commands::UpdateCommand:0x1138b24>

When I ran it again everything seemed fine. Then tried to install Merb and got the same message about needing RubyGems version 1.3.0 or higher.

Turns out there is a problem upgrading from RubyGems 1.1 and 1.2 when rubygems-update is not previously installed.

If you try the alternative update commands then you should be able to gem install Merb 1.0 ok.


$ sudo gem install rubygems-update
$ sudo update_rubygems

5 Reasons Why Rails Developers Will Survive the Credit Crunch

Written by Ben

So we are in the throws of an economic downturn that the media in the UK has named ‘the Credit Crunch’.

I read recently on Techcrunch about the angel investor Ron Conway sending an email to his portfolio companies offering advice for the immediate future.

There is no doubt that silicon valley is feeling the global financial crisis and ripples have been sent across the pond to the UK. I think that there will be reduced budgets and less investments in UK startups, no surprises there.
It’s not all doom and gloom, I don’t think the Credit Crunch will hit the tech industry as hard as it will other industries, but we are certainly in for months of belt tightening.
Read More »

‘rake notes’ for Rails 1.2.6 with RSpec

Written by Ben

I have been doing a bit of work with Rails 1.2.6 recently and I am missing one feature that I use regularly in Rails 2.1 and that is rake notes.

I use # TODO comments as todo list items within my code and then call rake notes to review them.
I find it really useful for putting todo items in context with the actual related code and being a bit forgetful, I can also use them as reminders to refactor and optimise bits of code later.

I have recently started using RSpec at work and was frustrated that I could not create notes in my spec files. So I extracted out the functionality of the rake notes task from Rails 2.1 and put it in a handy self contained rake file to be included into 1.2.6.

I then edited the directories that it searches to include the spec and story directories.

Done! rake notes for Rails 1.2.6 with Rspec.

Usage

Drop the code snippet below in its own rake file and put it in your lib/tasks directory, then rake spec:notes to see all your notes.

spec_notes.rake gist on github

I will warn you that it is not extensively tested so use it at your own risk!

I would like to extend the rake spec:notes task to search for notes in custom directories and integrate it into rails 2.1, but I am just short on time. Hopefully someone has already done it or would like to do it, if so let me know so I can use it.

Ruby Tip: Normalizing Hash Keys as Symbols

Written by Ben

Ruby hash keys can be any type of object apart from an integer, but typically they are used in two ways when coding a rails app.

With string keys:

{"a" => "hash"}

Or symbol keys:

{:a => "hash"}

When writing a method that uses a hash of arguments you should handle both styles of hashes. There are a number of reasons for this.

  • You work with other developers who have different coding styles and use either method.
  • More flexibility to fit with other bits of code.
  • Cover more bases and its less likely to break.
  • Generally a good design decision.

The easiest way to handle this situation is to normalize all the keys to symbols and Rails provides the symbolize_keys and symbolize_keys! in ActiveSupport for your coding pleasure.

The symbolize_keys method itself is useful to include in standalone ruby scripts and libraries, also its a good example of how to use Enumerable#inject for more complex stuff.

def symbolize_keys
  inject({}) do |options, (key, value)|
    options[(key.to_sym rescue key) || key] = value
    options
  end
end

A small tip that has come in handy on a few occasions.

Switch from SVN to Git with no history

Written by Ben

A while ago the team switched to git/github from subversion (svn), but we needed to get the latest copy of our code and leave behind the massive history to save space on github.

How?

I used the git svn command as follows:

  git svn clone <current_svn_revision>:HEAD <url_to_svn> 

Simply note down the latest svn revision number from the repository and use that to clone with.

The beauty of this method is you are now using git, but at any time you can run dcommit to commit changes back to the svn repository keeping that in sync.

Combating comment trolls with design

Written by Ben

I saw this today on the 37 signals blog and thought it was good use of design to combat troll comments.

Combating comment trolls with design

There must be some facility on their blog to flag up troll comments. Instead of reacting with more comments, which is what they want, design is used to cleverly to highlight and make the commenter look like a bit of a fool.

I like the way the text is greyed out subtly showing the comment is not as important as others around it. Also adding a troll dunce hat is genius, it makes the guy look silly and the best thing is he can do absolutely nothing about it.

I wonder if this kind of technique actually discourages troll behaviour?

BBC Music Artist Pages beta, help join the dots

Written by Ben

I think its brilliant what the Audio and Music team have achieved with the music artist beta pages. You can read posts byTom Scott and Matthew Shorter for more information.

I would like to echo the sentiments of Matthew by saying that this kind of service has a large amount of public value and is definitely something the BBC should be doing with licence fee money.

I am a big fan of crowd sourcing. Harnessing the potential audience that will visit these pages and coupling this with community-generated data will hopefully produce a really useful service. Pushing this data back into the community will hopefully encourage more people to add to the data in Wikipedia and Musicbrainz making the whole ecosystem stronger.

It is a great start with massive potential, so I encourage you to help out a little and linkup some of your favourite artists.
Here are the instructions below lifted from Matthew Shorter’s post.

  1. visit http://musicbrainz.org
  2. enter artist name in the “artist” field under “Search” on the left hand side
  3. click on the name you’re after on the list of results
  4. select the alphanumeric ID from the page’s URL, e.g. from http://musicbrainz.org/artist/4dca4bb2-23ba-4103-97e6-5810311db33a.html, select 4dca4bb2-23ba-4103-97e6-5810311db33a.
  5. paste the ID to the end of the URL http://www.bbc.co.uk/music/artists/, e.g. http://www.bbc.co.uk/music/artists/4dca4bb2-23ba-4103-97e6-5810311db33a

I only hope that we can do something similar on the TV side of things.