I started using the acts_as_ferret plugin for ruby on rails today. I had a a few issues, so here is how I solved them.

  1. script/plugin install svn:// does not work! – After successfully installing ferret using the gem, I tried to download the plugin, but my box could not connect. I am not sure if it is an error with my setup or what. So I had to browse the source tree in track and copy and past the files on my box.
  2. Rails will not start – After I copied across the plugin, Rails was complaining that it could not find the plugin acts_as_ferret. It turned out that the plugin directory I had made was not world readable, so rails could not read it. A quick chmod fixed that
  3. Site was not getting indexed – After putting the acts_as_ferret in the desired models, I searched for words that I knew existed and i was not getting any responses. I figured out that it was not being indexed. if the index directory does not exist than the plugin calls rebuild_index method. This is supposed to go through your database and create the index. The app was failing executing the rebuild_index method. I googled the error and came across this post It was an error because i was using Unicode. So I added the following to my environment.rb file and it has indexed the files :

ENV[‘LANG’] = ‘en_GB.UTF-8’

ENV[‘LC_TIME’] = ‘C’

All I have to do now is figure out how to use ferret 🙂




I needed a way to send emails to users if certain data in the system had not been updated for 4 hours.

I thought that RailsCron would be the best solution developed by Kyle Maxwell. Unfortunatly his site and wiki was down. So I could not see how to use it correctly, as the readme was a bit vauge. So I thought I would post some simple code here to help some people on how to use RailsCron.

First of all I wanted to use ActsAsBackground on a Model Class. Here is the code :

class Comment < ActiveRecord::Base
  # This is the key thing.  I am not sure why it does not use acts_as_background
  include ActsAsBackground
  # This defines what method you want to use
  background :deliver, :every => 1.minute

def self.deliver
   #code here

What I was confused on was how to use acts as background. I managed to find a cached version of Kyle’s page and see it in action. I am sure there is a reason that it is not acts_as_background and why you need the include directive.

The next thing took me a while to figure out as well :). To actually use RaisCron you need to start it with a rake command like so :

rake cron_start

The rest of the comands are in the readme file. I hope this helps someone out there.


Small Bug in acts_as_taggable with acts_as_versioned

I have come accross a bug if you are using acts_as_taggable and acts_as_versioned on the same model. For some reason acts_as_taggable triggers a new version to be stored in the version history. So it stores two identical versions every time. As soon as you turn off the tagging it works.

I have tried to get around the issue by using the method version_condition_met? in the model. I thought it worked but if the fields were null or blank it failed.

I will try a few more things and post the results here.


acts_as_taggable with different language tags

As part of my Rails project I needed to tag items in Chinese and in English. For obvious reasons I wanted to use the acts_as_taggable plugin (not the gem). I really like the way it works. It is very clean and elegant solution for tagging.

However my problem was how do I distinguish a Chinese tag from an English tag. I came up with a few solutions. One being to use the geotagging formula which would translate to Chinese_tag:English_tag. Initially this seemed like a good idea, But, it does seem a bit tied down. What if a user wanted to tag it with an English tag, but not the corresponding Chinese tag ?

So the simple solution I came up with was to add a language field (VARCHAR(2)) to the tag database. If it was a Chinese tag I would simply put ‘ch’ in the language and if it was English I would simply put ‘en’

Here is the actual change I made to the plugin :


 def tag_with(list, lang)
Tag.transaction do
taggings.destroy_all Tag.parse(list).each do |name|
if acts_as_taggable_options[:from]
tag_find = Tag.find_by_name_and_language(name,lang).on(self)
Tag.create(:name => name, :language =>lang).on(self)

As you can see this method takes an extra parameter ‘lang’. The change has been made in the else statement. It tries to find the tag with the language. If that fails then it creates the tag. This replaced a simple Tag.find_or_create_by_name(name).on(self)Its as simple as that. The tag_with method now accepts and saves the language field.

I also implemented these methods which are self explanatory :

def tag_chinese_list

tags.collect {|tag|" ") ? "'#{}'" : if tag.language =="ch" }.join(" ") }


The above method simply retrieves all of the Chinese tags. I have a similar one for English. I also added a find_tagged_with_chinese method. This is just a copy of the original find_tagged_with method with an extra AND language =”ch” at the end.

I should really re-factor the code. For example making the tag_list take a language parameter.

I hope this helps someone.


FCKeditor on Rails

Hi again,

I found myself needing a WYSIWYG editor for the rails app I am developing. I thought FCKeditor is great. I installed it by following these instructions

All was well, but I could not get the file upload interface to work under Rails. So I did some searching and came across this project. Michael Moen had got it all to work ver nicely.

FCKeditor is fully integrated into my app. Nice!




I have made a lot of progress with Ruby on Rails. I have to say that I have taken a real liking to this framework. I have to applaud the Rails team and community.

As is expected I have come across a few difficulties. But I have always got a answer on the Rails mailing list. Any big software project needs to have such a community to back it up, otherwise new people will never come on the scene.

Hopefully my next post will run through a small tutorial of editing and saving a HTML Form using RJS templates. It is unbelievable easy.


Ruby on Rails First Thoughts

Well my head has been in RoR for about 4 days. I have to say I have found it quite difficult to learn. I think that is because I have been relying on tutorials and wiki entries. I think if I would have read the rails book things would be alot easier (but slower ?). I have not got to grips with it fully. I am still trying my best to learn some of the inner workings.

Rails 1.1was released a couple of days ago. It has a bunch of cool new features. But I am not sure I am at the stage of using half of the features. Nevertheless I have upgraded 🙂 with a little bit of difficulties. This was due the version of Ruby I had was not supported. I had version 1.8.3, put that is not supported and because I was Ubuntu, I found it difficult to update it.

Ruby on Rails …?

Ruby on Rails Logo

Although you may have gathered I am looking into Python frameworks. I have just been asked at work, if we can use Ruby on Rails as a platform to develop a pilot project we are developing. (I can’t give any details, just to say that it will be a bilingual site 🙂

So this leaves me with learning two very different frameworks and languages. Such is life. I can say that the documentation for Rails is awesome, compared to TurboGrears.
It is going to be an interesting few months …

Very Interesting Forum Post

I have just been reading a very interesting forum post concerning Python Frameworks. It has a number of views from different python camps.

So Far…


I have read a very interesting post about the Pylons framework here. It is done by one of its creators. The analysis is very detailed. But the analysis confirms my initial concerns that Pylons is not really there yet, but they are going in the right direction, especially with support for Paste

For those of you that don’t know. TurboGrears have released their infamous 0.9a release It has a lot of new features, which all look very cool indeed.

I think along with this release and with the experimental support for sqlalchemy TurboGears is going in the right direction for me. I have decided that this will be the first python framework that I will play about with :).

I will probably try an make that 20 minute wiki first, so i can get a feel for the framework.