Archive for July, 2007

Ruby issues and backgroundrb

Posted in backgroundrb, ruby, rubyonrails on July 29th, 2007 by Prateek Dayal – 1 Comment

Well on a fine saturday morning, i set a breakpoint in my code so that I can read the values of params being passed on a form submit (i wanted to try checkbox arrays) and I get an error saying breakpoints not supported in ruby-1.8.5. I had installed ruby sometime back on my ubuntu fiesty fawn and i decided to upgrade it to 1.8.6 because that is what i am using in windows (instant rails). I grab a new package from ruby-lang.org and install it (source package).

Trouble begins … nothing works fine. There is no rails !!!. I grab rubygems, install that and install rails and other gems that i need. Now i open script/console and it says


/usr/local/lib/ruby/1.8/irb/completion.rb:10:in `require': no such file to load -- readline (LoadError)

After a lot of effort and searching on the web, I found instructions here that fix it. Steps 27-33 if you wanna skip everything else.

Now to backgroundrb: It is so damn tough to figure out where to install backgroundrb from. I think I had installed it from rubyforge or someplace and turns out if was an older version. I finally grabbed the latest version from trunk from here and looks like it is. I could create an example worker and call it from my application controller and pass some data back from worker to the application using the results hash.

I find the backgroundrb documentation here to be quite useful. Next I will try to do some MP3 encoding stuff using backgroundrb

Popularity: 8% [?]

Active record and Mongrel Upload Progress Plugin

Posted in mongrel, rubyonrails, technical, upload_progress on July 24th, 2007 by Prateek Dayal – 1 Comment

Muziboo is a pretty upload intensive website. Also there is the issue of resampling the MP3 file so that the flash player plays it well (Frequencies not multiple of 11025 Hz are ‘chipmunked’ in flash). I started looking into the mongrel_upload_progress plugin yesterday and found this demo to get me started. It works fine and I could successfully integrate it with my upload page.

However there is an issue. What happens if there is an activerecord validation error. In that case the error messages have to be shown back on the upload page. This is something that I have not been able to figure out yet. The upload controller uses a responds_to_parent function and I don’t understand it fully yet. If I do not reload the page, the page won’t stop polling mongrel for upload progress. If I do reload the page, the error messages go away :(

I will try to figure this out soon and will post the progress here …

Popularity: 9% [?]

Tag clouds with acts_as_taggable for different Taggable Types

Posted in acts_as_taggable, rubyonrails, technical on July 22nd, 2007 by Prateek Dayal – 4 Comments

So you are building a cool new web 2.0 startup and want to have the cool tagging feature. If you are using ruby on rails, you can use Acts_As_Taggable Plugin . There is a neat way to build a tag cloud explained here.

Now acts_as_taggable uses a field called taggable_type to know what object this tag is applied to. For example, you can have tags for videos, audio blah blah blah. Now you want to build a different tag cloud for each of these categories. The steps mentioned on the site do not support this. However a small modification in the SQL query used in file lib/tag.rb in the function self.tags(option={}) can achieve this. The original query is like this


def self.tags(options = {})
query = "select tags.id, name, count(*) as count"
query << " from taggings, tags"
query << " where tags.id = tag_id"
query << " group by tag_id"
query << " order by #{options[:order]}" if options[:order] != nil
query << " limit #{options[:limit]}" if options[:limit] != nil
tags = Tag.find_by_sql(query)
end

Change this to


query = "select tags.id, name, count(*) as count"
query << " from taggings, tags"
query << " where tags.id = tag_id and taggable_type = "+"'"+options[:type]+"' "
query << " group by tag_id"
query << " order by #{options[:order]}" if options[:order] != nil
query << " limit #{options[:limit]}" if options[:limit] != nil
tags = Tag.find_by_sql(query)

This adds the select based on taggable_type to the query and you can pass it as an option in the options hash. Now to build a tag cloud for audio model instead of the function call

@tags = Tag.tags(:limit => 100, :order => "name desc")

write

@tags = Tag.tags(:limit => 100, :order => "name desc",:type='Audio')

This will pull out tags only for audio and you can use this to build a tags cloud as exaplained in the post above

This is a small but useful modification. Do let me know if it can be further improved :)

Popularity: 12% [?]

Finding a webhost !

Posted in rubyonrails, technical, webhosting on July 22nd, 2007 by Prateek Dayal – 2 Comments

Hi,

So this is my another new blog :)

Last one month or so has been a lot of experimentation in terms of webhosts. I tried godaddy.com, dreamhost and hostingrails.com. Here is my take on all of them. Again this is just a personal viewpoint and may/may not apply to other people. Depends what you are looking for. In general I feel there are lots of hosts and one can always find out what they are looking for. It however helps to know for sure what you are looking for (lots of webspace vs speed vs support for some language/platform and ofcourse how much you are willing to spend)

Godaddy:

They I think are one of the big players however I found it very surprising that they do not give shell access in any of their shared hosting plans. This may be of importance to a lot of people, so be sure. In terms of speed etc, they are fine. Also I think they are good for domain registrations etc. I got a domain for $7.17 or something through them. Like other hosts, they do give you a lot of softwares that can be installed by a single click

Dreamhost:

These guys are quite big too and for the money that you pay, you cannot find more space and more bandwidth easily anywhere else. They give shell access and have a great control panel but the only drawback may be (again applies to only few) that their rubyonrails support is not very great. You can upgrade plans only in terms of space/bw but you cannot add on more memory etc to your account (to run a mongreal instance for example)

HostingRails:

Hostingrails is pretty good for Ruby on Rails hosting. They have good set of documentation on how to get your rails application online (existing or new) and also how to debug a lot of issues. Their support knows rails well and you can find that out by glancing over their forums. However you may not get as much space/bw as you get with dreamhost. One thing i do like is that you can upgrade plans and also get more static memory for your account. So this may be useful if you want to run mongrel or other applications that require more RAM. Also its pretty easy to upgrade your plans and they can even help you upgrade to a dedicated server when you want. They say that they can get you online within 24 hours even when you move to a dedicated server.

Lot of the above information is what I found out reading their docs and forums and may not be correct/not stay correct. Please do let me know your comments and I will update the article.

PS: I am currently with hostingrails.com where I am hosting my new internet venture Muziboo.com. I plan to finish all the basic functionality in a month may be. Do check it out and let me know what you feel. You can read Muziboo Blog to know more about what we are trying to achieve there.

Popularity: 6% [?]