Archive for June, 2006|Monthly archive page

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!