A story of just another web developer

Attach Files Using Paperclip

Posted on May 05, 2008

I have used a number of plugins to attach files to applications with Rails. These include file_upload (remember that) , acts_as_attachment and attachment_fu.

I came across a plugin called Paperclip a few months ago. It looked like the best solution I have seen to simple file attachments since file_upload and it did not rely on the memory monster that is RMagick. I said to myself the next project I work on, paperclip is the way to go.

I have recently had the opportunity to use it on a project I am working on. I have to say that I am very impressed so far, and if any of you have not used it yet, I would advise you to give it a go.

In terms of tutorials, I would highly advise that you start with this tutorial by Jim Neath. I have to say that I was a bit confused in the beginning, but this tutorial helped me on my way.

Image Permissions

As part of the project I needed to direct all requests to the image through an action, to check if the current user that is logged in has permission to see the image. I had a few issues doing this, so I thought I would share how I did that here.

Model:



class User < ActiveRecord::Base

  has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" } ,
  :url => "/images/show/:id/:style/",
  :path => "#{RAILS_ROOT}/attachments/:class/:id/:style/:basename.:extension" 

end

I removed all the files from the public directory. That way I was sure that no one can get access to it. That is where the :path => Hash is used. I stored the images in a folder called ‘attachments’ contained within the Rails root folder Here is a list of what the url params are used for:

  • class—This is the name of the class the attachment is associated to. In this case User
  • id—This is the unique ID of the model the attachment is associated to.
  • style—The name of the style. In this case we would have a folder called ‘thumb’ and a folder called ‘medium’ and also a folder called ‘original’
  • basename—The file name without the file extension
  • extension—Filename extension
For some reason I could not get the :url hash to work when I used url placeholders. It just did not seem to want to pass on the parameters to my controller. So the only option I had was to create the url using the good old fashioned way.

The :url hash is directing all image requests to the images controller, making sure to pass all the relevant parameters along with it.

Next I am going to detail the very simple controller :



class ImagesController < ApplicationController

  def show
    if logged_in? && current_user.allowed_to_view_image?(params[:id])
      send_file(current_user.photo.path(params[:style]) , :disposition => 'inline')
    else
      '#'
    end    
  end 
end

As you can see it is very simple. All requests are passed to the show action. The first thing it does is check to see if the user is allowed to see the image using a method called on the User object (I have not detailed it here as it will be different for everybody).

Once permission has been granted simply display an inline send_file request with the same directory structure as defined in the :path url.

Linking

As I am not using Rails 2 for this project, I came across a problem with using image_tag as it saw fit to append a .png to the request. I am not sure how to turn this off and I know it has been ‘fixed’ in Rails 2. My only current solution is to use the old school “img” tag in my views.

Let me know your thoughts

UPDATE

As you can see from Jon Yurek’s (creator of this plugin) comment, the old way I was doing it was not necessary. So I have updated the code to reflect those changes and tested it. However if you do this, you will also have to add an extra Route to your config. Here is the one I added :


  map.connect '/images/:action/:id/:style' , :controller => 'images'

Thanks Jon!

Hamza

Arabibay.com & Responds to parent error

Posted on December 26, 2007

I know it has been a very very long time since I last posted. Quite a few things have been happening in my life the past 4 months. But I will not bore you with the details :)

I have been working on a few sites lately. The latest project which has just been made live is Arabibay.com

Arabibay is a free classifieds website that allows people to post adverts around the world. As you can tell by the title, it is aimed at the Middle East, but all countries are supported. Check it out and leave some feedback, as always your comments are greatly appreciated.

Responds To Parent

As I can’t post without mentioning something technical (however insignificant). For this project I needed to allow users the ability to upload images to the system via AJAX. I came across this very good tutorial and a really useful plugin called Responds to Parent .

However I had a few issues setting up the plugin. I installed the plugin like so


  script/plugin install http://responds-to-parent.googlecode.com/svn/trunk/ 

It installed it into a folder called trunk, so immediately I changed the folder name to responds-to-parent. So far so good.

I then tried to restart the app but the app failed to start with this plugin installed. So I looked around on the net for the error I was getting, but nothing came about.

To cut a long story short, I needed to rename the folder to responds_to_parent as in the init.rb, it is obviously requiring RespondsToParent, which assumes responds_to_parent.

Hopefully this can save someone some time :)

Future Posts

I know that I have said this before, but now that I have settled down a bit, I am hoping to blog on a more regular basis.

Hamza

attachment_fu Thumbnail Size

Posted on May 18, 2007

As I mentioned earlier, when working with attachment_fu and image science the width and height of thumbnails were not being set correctly. So here is a method that I use to make sure that the data is set.



def set_image_dimensions
  if @image.width.blank? || @image.height.blank?
    ImageScience.with_image("#{RAILS_ROOT}/public/" << @image.public_filename) do |img|
      @image.height = img.height
      @image.width = img.width
    end
    @image.update_attribute('height',@image.height)
    @image.update_attribute('width',@image.width)
  end
end

Is anyone doing it differently ? Has this been addressed ?

Comments welcome.

Hamza

Fun with attachment_fu

Posted on May 12, 2007

As I mentioned in my previous post I am going to outline my experiences with attachment_fu. I will try to extend the brilliant tutorial that first introduced me to attachment_fu and to ImageScience.

The problem

The simple problem I had was that I wanted to be able to associate a image (and thumbnails) to a article. Although this sounds easy, I had some trouble along the way (hence the post).

Write the Migration models



class CreateImages < ActiveRecord::Migration

  def self.up
    create_table :images do |t|
      t.column :parent_id,  :integer
      t.column :content_type, :string
      t.column :filename, :string    
      t.column :thumbnail, :string 
      t.column :size, :integer
      t.column :width, :integer
      t.column :height, :integer
      t.column :content_id, :integer
    end
  end

  def self.down
    drop_table :images
  end
end

class CreateContents < ActiveRecord::Migration

  def self.up
    create_table :contents do |t|
      t.column :title , :string
      t.column :summary, :text
      t.column :body, :text
      t.column :status, :string
    end
  end

  def self.down
    drop_table :contents
  end
end

The only thing to note here is that I have placed a content_id foreign key into the image table, to allow them to be linked.

Write the models

The models are going to have two different associations, both of type has_one. The first association has an extra condition that allows it to only return the parent image, the second association returns the parent image and all its associated thumbnails.


class Content < ActiveRecord::Base
  has_one :image, :conditions => 'parent_id is null'
  has_one :all_images, :class_name => 'Image' # all photos + thumbnails
end

The Image model has the standard attachment_fu declaration along side the thumbnail declarations.


class Image < ActiveRecord::Base
  has_attachment :content_type => :image, 
                   :storage => :file_system,
                   :thumbnails => { :thumb => '107x76>'}    
end

Write the form view


<% form_for(:content, :url => { :action=>'create'}, 
                      :html => { :multipart => true }) do |f| -%>

<p>
  <label for="title">Title</label><br/>
  <%= f.text_field :title %>
</p>

<p>
  <label for="summary">Summary</label><br/>
  <%= f.text_area :summary %>
</p>

<p>
  <label for="title">Body</label><br/>
  <%= f.text_area :body %>
</p>

 <p>
    <label for="image">Associate Image:</label><br/>
    <%= file_field 'image','uploaded_data' %>
  </p>
  <p>
    <%= submit_tag 'Create' %>
  </p>
<% end -%>

As you can see I have placed the image in a different hash, as you can’t associate the file directly to the model. All of the other fields are pretty standard. To test out the update method you just need to change the URL to point to the update method and pass it the content id. I will leave it out here for simplicity.

Write the controller

This is where I was having most trouble. No matter what I did, it just did not save the dam thing. So here is my create and update actions in my contents controller


def create
    #Create the content
    @content = Content.new(params[:content])
    respond_to do |format|
      if @content.save
        #Here comes the important bit!
        if !params[:image][:uploaded_data].blank?
          @content.image = Image.create(params[:image])       
        end
        flash[:notice] = 'Content was successfully created.'
        format.html { redirect_to :action=>'show', :id=>@content }
      else
        format.html { render :action => "new" }
      end
    end
  end  

OK that was not that hard :). But I was having problems on the update action. The create action seemed to be working fine. Here is the update action.


  def update
      @content = Content.find(params[:id])
      respond_to do |format|
        if @content.update_attributes(params[:content])
          # Heres the important bit!
          if !params[:image][:uploaded_data].blank?
            #find current image
            @image = @content.image ||= Image.new
            @image = @content.image.build(params[:image])
            @image.save       
          end
          format.html { redirect_to :action=>'show', :id=>@content }
        else
          format.html { render :action => "edit" }
        end
      end
    end
 

As you can see I am using the build method to create the image. I am not sure why, but If I put the build method into the create method it just fails. Oh yeah and in a real application I would group the image methods into their own respective functions.

The content view

So for all the code we have written we can now show the images that are associated with a specific article.


  <h2><%=@content.title%> </h2>
  <p><%=@content.summary%></p>

<%if !@content.image.blank?%> 
  <p>
    Original Image : <%=image_tag @content.image.public_filename %>
  </p>
  <p>
    Thumbnail : <%=image_tag @content.image.public_filename(:thumb) %>
  </p>
  <p>
    <%=@content.body%>
  </p>
<%end%>

Outstanding issues

There a few bugs in attachment_fu that I came across, they are :

  • The width and the height are not being set for thumbnails when I use ImageScience and attachment_fu.
  • The size (in the database field) of the thumbnails are not correct. They just display the original file’s image size.

I will blog again regarding these issues in the near future.

Code

In writing this post, I made a test rails app so I could make sure that the code I have above is correct and compiles without any errors. If anyone wants this I can put a link to it here, just leave a comment.

As usual all comments welcome.

Hamza

Compiling FreeImage on OS X (Power PC)

Posted on May 03, 2007

I was very excited when I read this excellent blog post by Mike Clark, detailing how to use attachment_fu. Even more interesting was that I did not have to use RMagick anymore. I could not quite get it working correctly for me, not to mention the reported memory leaks and CPU cycles it takes up.

Instead I could use ImageScience which is a small Inline Ruby library that re-sizes images. However for me to install ImageScience I had to install FreeImage on my mac.

Whatever I did I could not get it installed on my power pc mac laptop. I tried the instructions given, but nothing worked. I then noticed that there was a problem with the current release for macs and was advised to use the subversion repository. I tried to do this, but whenever I tried to run make, it just kept on complaining that it can’t find the libs that were related to the Intel 386 platform. So the make file was not correctly working for the power pc architecture.

I posted to the forums, and luckily Josh emailed me with a makefile that stripped out all of the 386 calls (i tried this myself but did not get very far). The new make file did the trick. Thanks Josh :)

So if anyone else is having the same problem here is the make file

In my next post I will be talking about my adventures with attachment_fu and extending the tutorial laid out in Mike Clark’s blog post.

Hamza

New Blog Url

Posted on May 02, 2007

I have finally taken the step and set up my own blog on a virtual server I have kicking about.

My old blog was here :

http://hamzakc.wordpress.com

Now the new address is here :

http://hamza.khan-cheema.com

I thought I would put the domain name I bought into use.

I choose the best Rails blogging platform : Mephisto I have to say I am very impressed with this indeed. I hae even set up proper code blocks with syntax highlighting thanks to dann webb

I have updated the feed in feedburner, (in the backend) so those of you who are subscribed will not notice any different as the feedburner address is still the same.

Hopefully now that I have this new platform installed I will blog more often. I have a blog that I want to write about attachment_fu and image science.

I have not imported the comments yet, but I will do soon.

Hamza

Rails Autocomplete Tag List

Posted on March 03, 2007

I wanted to make an autocomplete text field on a edit form that listed all of the tags that are already entered in the system. It is quite simple, but I thought I would share it to save some time for someone. Of course we are using acts_as_taggable

The controller :

def auto_complete_for_tag_name
  auto_complete_responder_for_tag_name params[:tag][:name]
end

def auto_complete_responder_for_tag_name(value)
  @tag_list = Tag.find(:all,
  :conditions => [ ‘LOWER(name) LIKE ?’,
  ‘%’ + value.downcase + ‘%’ ],
  :order => ‘name ASC’,
  :limit => 10)

  render :partial => ‘tags’

end

def edit
  @content = Content.find(params[:id])
  @tag = Tag.new
  @tag.name = @content.tag_list
end

To retrieve the current tag list you need to make a new Tag object and add the tag list to it.

In my _tag.rhtml partial :


<ul class=”tags”>
  <% for tag in @tag_list do -%>
    <li class=”contact”><div class=”name”><%=h tag.name %> </div></li>
  <% end -%>
</ul>

In My _form.rhtml


<p>Tags (Seperate with space)<br/>

<%= text_field_with_auto_complete :tag, :name,
{:size =>50, :skip_style => true},
{:indicator =>’searchIndicator’,
:tokens => [’ ‘, ‘\n’]} %>
<%= image_tag(”/images/indicator2.gif”, :id => ’searchIndicator’, :style => ‘display:none;’) %>
</p>

You will notice that I have added a search indicator, which you will need to have on your system.

Thats how easy it is :)

Hamza

Create Triple DES SecretKey in Java

Posted on December 29, 2006

For a project at work, I needed to integrate our website with another web application. The web application in question also had their own built in user management system. For seamless integration we wanted our users to only have to log in once.

As the web application was quite a large application, they already had a REST api that allowed you to supply them with a encrypted token in the url that authenticated you on their systems. You simply had to encrypt the user id (on their system) and the current time stamp.

As I had never done anything to do with encryption before in Java. I had to learn from scratch.

The token had to be encrypted with Triple DES CBC scheme. They supply you with an access key. Here is where the problem lay. I could find quite a few examples that allowed you to use the inbuilt key generator in Java, but what about if you have your own key (our access key). This was a bit more difficult to find, so I thought I would blog a code snipit here. In the end it turned out to simple (it always is :)

The key needed to be Triple DES (DESede)


String keyString =”4d89g13j4j91j27c582ji69373y788r6″; // I made this key up by the way!

byte[] keyB = new byte[24]; // a Triple DES key is a byte[24] array

for (int i = 0; i < keyString.length() && i < keyB.length; i++) {
  keyB[i] = (byte) keyString.charAt(i);
}
// Make the Key
SecretKey key = new SecretKeySpec(keyB, “DESede”);

A good resource that I found was here

Hamza

Atheros Wireless Setup - Ubuntu

Posted on December 11, 2006

As I stated earlier, I just bought a new laptop and installed Ubuntu 6.10 (Edgy Eft) on it. All was working apart from the wireless connection. The Laptop comes with a Atheros wireless card. Ubuntu also comes installed with madwifi drivers for the card. So in theory things should just work, right ? Well no. The version of the wireless card I have (I do not have the version to hand) does not work with the current ubuntu package of madWiFi drivers.

So this is a quick step by step tutorial on how I got things to work nicely :

  • Get the g++ compiler : sudo apt-get install build-essential
  • Download subversion : sudo apt-get install subversion
  • Create directory to store the drivers and navigate to it.
  • Download latest madwifi drivers using subversion : subversion svn checkout http://svn.madwifi.org/trunk madwifi
  • Get the current Kernel you are running : uname -r
  • Navigate to the correct lib directory : cd /lib/modules/$(uname -r) (use the output from the previous step to get the directory)
  • Delete the net lib files : sudo rm -rf net
  • Delete the madwifi files : sudo rm -rf madwifi
  • Delete this folder if it exists : sudo rm -rf madwifi-ng
  • Find the modules currently installed that you need to unload : lsmod | grep ath
  • From this output above issue a rmmod command for all the modules : sudo rmmod modulename
  • Go back to where you downloaded the new subversion drivers and run : sudo make and then sudo make install answer yes to remove the old module.
  • Load all of the modules you have just unloaded using modprobe. These should be: sudo modprobe ath_pci sudo modprobe ath_rate_sample sudo modprobe wlan sudo modprobe ath_hal
  • Check to see if modules have been loaded by typing dmesg and looking at the system log.
  • Open up network gui in Ubuntu and enable the wifi card and set the sessid

The card should now be configured. However if you want a dock applet that informs you how much strength your wireless card has, I would suggest netapplet.

I hope this has helped someone. This took me about 2-3 hours to get working!

Hamza

PC Nextday Zoostorm 4-5701 17″ Laptop - Wireless problem

Posted on December 08, 2006

So I bought a 17 inch Zoostorm laptop from PCNextday . It got 5 stars out of 5 from Computer Shopper and it worked out about £200 cheaper the a 17″ Dell laptop.

All was well, I was aware that they did have a bad reputation for customer service, but I thought I would risk it as the saving was too much.

The laptop came within 3 days of me ordering it. This was a surprise as they said that it can take up to take 3 weeks.

The laptop was working well, I was impressed with the screen (even though computer shopper said it was dull). However I was having a problem with the built in wireless card (Atheros). It was getting a very low signal even though I was sitting next to the wireless router. I first thought this was my router, so I asked someone else to test it and they reported the same problems. I then went and upgraded the software to the latest driver. The windows drivers are difficult to find so here is a good resource . But this had no effect. So after tearing my hair out I could not figure it out I emailed the technical support at pcnextday. They took a long time to respond, but their response was worth the wait. They basically said to check weather the wireless card was installed correctly and gave me these pictures :

So I unscrewed the laptop and checked it. I found out that the card was in the correct place, however the antenna was connected to the wrong point in the card. So I changed that and tested it. Unfortunately this did not work. As there were two wires that were black, I thought maybe the person who installed it made a mistake and attached the wrong wire. So I added the other wire and it worked. Now I have an excellent signal :)

I hope this experience helps someone. I think pcnextday need to work on their quality control :)

I have installed Ubuntu 6.10 on the laptop. All of the things seem to work. I had to do some configuration to get the wireless card to work though, but that is another blog post.

Hamza

Dual Monitor Setup - Ubuntu ATI

Posted on October 16, 2006

I wanted to get my dual monitor setup working at work. I have the latest veresion of Ubuntu (6.06 LTS – the Dapper Drake).

aticonfig This is a really easy way to get it working. I have a Dell Optiplex GX620 with a ATI graphics card. The card can support a dual monitor setup.

It turns out that ati have supplied a program (aticonfig) that inspects your current xorg.conf file and then changes it to allow for dual monitor setup.

Here is what you do in a terminal window :

sudo aticonfig –initial=dual-head –screen-layout=left


You may want to change the left to be right, dependendant on where your main monitor is (monitor 0).

As I have two monitors that support diffrent resolutions, the setup was using 1024×768 on both screens and I could not drag windows accross screens (I could drag the mouse :)

To address the dragging window issue, I did this after I executed the first command :

sudo aticonfig –dtop=horizontal, reverse –overlay-on=1

If you look at the help page for aticonfig, you will see that dtop can take different parameters. Because my second screen was to the left of monitor 0, I had horizontal, reverse But if it was to the right I would have used horizontal only.

To address the screen resolution do this (please see note)

sudo aticonfig –resolution=0,1600×1200,1280×1024,1024×768

This now sets my monitor 0 to be able to support 1600×1200 resolution. My smaller monitor (monitor 1) will use 1024×768, which is what I want. You can simply change where it says 0 to be 1 This will now change monitor 1.

Now simply restart gdm to see the effects. Or if you can’t do that, just restart the machine.

Note Before you start changing the resolution, you need to know which is defined as monitor 0. As in my case monitor 0 supports a higher resolution then monitor 1. The easy way to find this out is to do the first two steps, start up and then the monitor with the menubar on top of it is monitor 0. If it is not the monitor you wanted, you can simply swap around the vga cables that go into the back of the video card There is a way to do it by editing the xorg.conf, but this is supposed to be a simple way of doing it :)

I hope this helps someone!

Hamza

RailsConf, My thoughts

Posted on September 15, 2006

I have just got home from two very exciting days at the rubyconf conference in London. Here are a few observations and just a few things I have learnt.

Observations I am not sure why, but I had a distinct impression that the majority of attendees would have been from Europe. However I seemed to come across people from the US or Canada. People who have come over from the states especially for the conference or people who are making it part of their vacation. Not that this is a bad thing. In fact it showed me that they were really committed to Rails and to Ruby. I have to say if my company was not paying for my ticket, I would never have dreamed of going to the conference. Maybe I need to get more involved :)

As this is my first conference, I was not sure what to expect. It was an entire new experience. I was pleasantly surprised by the organisation of the conference by skillsmatter and also by the excellent calibre of the speakers. As I am new to the ruby world, I did not know the speakers (apart from David H), this conference allowed me to put faces and personalities to these very influential people within the Rails / Ruby community.

I got to see the Rails core team. This was a real eye opener for me, as I had no idea who they were or what their thoughts were for the future of Rails (I know I should read more).

Then comes David H’s talk. I have to say that I was impressed with David’s ideas and the way he presented himself. I really like the RESTFUL stuff and ActiveResource and also the Simply Helper. For those of you that don’t know, this is a way of putting conventions into the view layer like he has just done for the controller using REST.

Things I learned

Overall I have to say that I did learn allot (especially about Ruby)

  • Rails 1.2 is to be released very soon and is going to depreciate a whole bunch of methods.
  • In Rails 2.0 these deprecated methods will be removed.
  • 1.2 is going to heavily push the REST stuff.
  • Routing has completely been rewritten as it was a bottleneck. This is to be released in 1.2
  • The goals of ActiveResource, It is not going to ship with Rails 1.2, maybe 2.0 ?
  • With all the restful work on the controllers, the view started to look dated, so they have developed SimplyHelper, which is a convention for views.
  • Rails speaks ‘C’ – This was a talk I attended. I think things like this are very important. If we have a very complex algorithm or we have some legacy C systems, we need to be able to call C code from Ruby. In the Python CMS world Zope does this for a lot of complex operations (as far as I remember, correct me if I am wrong). 4 different approaches were mentioned. I noted that SWIG seemed to be one of the better options (and it supports c++).
  • If you are using C to do a big CPU intensive task, or a task that will take a while to complete, then you need to use BackgroundDRB. This allows you to spawn requests in the background (surprise,surprise). So in a web app the client gets a response straight away, so he knows something is happening , a progress bar would be a good indicator in this situation.
  • I really enjoyed the talk about high performance. I always wondered if anyone had deployed Rails apps, which had to handle over a million hits per day. Well James Cox seemed to have allot of experience in this field, and he shared some tips with us. I will mention a few here.
    • Speed Perceived – This is to use Ajax to make the app perceive fast to the user. The user will not know.
    • Always use :select, :limit and :offset in your queries.
    • Try and use lazy loading (:include).
    • MEMCACHED – Basically always use this as much as possible, he really emphasised this point.
    • Avoid shared hosting (obvious).
    • Page Caching – BAD – Avoid this as it is a nightmare to clean up.
    • Fragment Caching – Is better then page caching, but their are scalability issues
    • 8 server Gem (server architecture) – 2 x Proxy / Web static servers, 4 x Application servers, 2x Database servers with database replication.
    • Session management – use memcache, not the database store
    • If you have one server use Apache (fcgi), but this does not scale well, so for multiple machines use mongrel.
    • Put Google Analytics in its own iframe, this will avoid your app waiting to show the page because it is retrieving the js from google.
  • Django
    • Really cool!
    • Has built in user and groups in the framework
    • Uses python code to define database schema. This allows them to add rich data models. So you can define an upload field or a url field, the system will automatically know what to do with this field. This allows them to auto generate the admin interface to such a high level and what streamlined is trying to replicate for Rails.
    • Reusable template views with hierarchy functionality.
    • Try and not use AJAX in the admin section, as you do not know what kind of PC your publishers are going to publish from (old, etc.)

Please comment if you found this useful or not. Hamza

RailsConf

Posted on September 13, 2006

I am really excited that I am going to RailsConf in London! Its going to be my first tech conference :)

Hopefully I can write some thoughts about it on this blog.

Hamza

Delicious with Ruby on Rails - JSON

Posted on September 13, 2006

I recently (well about a month ago!) read a very good post that informs you how to add your delicious links to your rails app.

I was using that method and all was well, until I got a request that the links should open in a new window. With the simple html access to my links, that was not an option you can pass. So I had to resort to using something more complicated; JSON seemed the easiest for me to read in and manipulate.

I would advise you to follow this tutorial and then come back here and see how the code can be changed to use JSON instead of the HTML api.

You will need to install the JSON ruby library first.

gem install json

If that does not work just download it from here and run the install script.

Here is the modified method


def delicious_links(limit ="20", aclass="grey")
    begin
      unless read_fragment(:action => 'delicious_links')
        logger.info "Getting new delicious_links" 
        require "open-uri" 
        require 'json'
        @delicious_links = "" 
        link = "http://del.icio.us/feeds/json/YOUR_USERNAME_HERE?raw=true&count="+limit
        @jsonObject = "" 

        open(link) {|f|
          f.each_line {|line| @jsonObject += line }
        }
        @urls = parse(@jsonObject)

        for i in 0...@urls.length
          @url_obj = @urls.fetch(i)
          url ="" 
          title ="" 
          tags ="" 
          @url_obj.each {|key, value|  
           url = value if key == "u" 
           title = value if key == "d" 
           tags = value if key == "t" 
          }
          @delicious_links += "<div class=\"blogSideBarLink\">" + "<a href= \""+url+"\" target=\"blank_\" class=\""+aclass+"\">"+ title+"</a></div>"            
        end
      end
    rescue
      @delicious_links = "Not available @ this time" 
    end
    logger.info "delicious_links finished" 
    render_without_layout
  end

Search problems

Posted on July 09, 2006

In my last post I said that I was using acts_as_ferret. However I was finding it difficult to create an index for a certain section of the site. I think this was due to me having null fields some of the database fields. I could nt change this.

When I was having problems I turned to acts_as_searchable . As the post states the search plugin uses HyperEstraier which is an opensource search engine. It seems to be very good and above all (for me) the UTF support seems excellent. This is demenstroated by having a Japenese language search demo on their site.

I managed to get it to work :) I will post how in the next couple of days.

My first thoughs about HyperEstraier is that it has some very good features, but most of the features I am not going to use in the near future. Overall the set up is a bit more invloved then ferret, this is because you need to run a deamon.

More thoughts soon!

Hamza