Thursday, March 23, 2006

To Open Source or Not to Open Source?

I have been receviving a lot of feedback on and based on the feedback, I have one question:

Should I open source my project? What are benefits / drawbacks?

Adoppt employs many principles that I have learned over the years. Alongwith my upcoming Pro Rails book, it will be something nice to give back to the community.

So far I think I would like to Open Source the software only for personal use and place a licensing fee for commercial use. Is that possible with Open Source? I know MySQL does something like this.

If I do Open Source it, should I host the code myself or put it on Sourceforge or Rubyforge?

Questions / Ideas / Experiences / Suggestions Welcome


MVC - Model View Controller Architecture

Here's a diagram I made to help explain MVC architecture to beginners.

If the Model, View Controller (MVC) terminology bothers you, you may use the alternate vocabulary until you can feel comfortable. For instance, as depicted in the figure above, you may refer to "controller" as "input", "model" as "processor" or "processing" and "view" as "output".

So in other words, controller receives the input, passes it to the model for processing, or to the view for output.


Tuesday, March 21, 2006

What the people want

These are some questions I have received about what people want to learn about Ruby on Rails, after I asked what people were interested in a post made yesterday to my MySQL blog entitled, Pro Rails and Applied Ruby on Rails: What do you want to learn? Please don't hesitate to send me your own questions and topics about Ruby, Ruby on Rails, and AJAX you would like to see covered in my upcoming book Pro Rails and Applied Ruby on Rails. Send questions to softwareengineer99 at yahoo dot com.

· How to install rails
· How to start an application
· What should I be familiar with before starting?
· How to install plugins (gems)
· How long will it take me to learn
· how to make a blog application
· how to make a forum application
· how to make a messaging system
· how to make a tagging system
· what if I don’t know OO?
· Is ROR different than Ruby?
· How do I connect to databases in Ruby OR
· What databases can I use with ROR?
· How do I paginate documents in ROR
· How do I made a class?
· What is a class?
· What are attributes?
· What are variables?
· What are functions?
· What is MVC
· What are models?
· What are views?
· What are controllers?
· How are they used together?
· How do I validate things in ROR?
· What is HABTM?
· will my application work on multiple browsers
· can I use ROR on a Mac? Windows? Linux?
· Can I scale my application?
· What are normalized tables
· How do I make normalized tables?
· can I use ROR with more than one database?
· how do I use AJAX with ROR
· What is AJAX?
· What is Ajax used for?
· Is there a ROR community to turn to for help?
· What is a Rails Engine?
· How can I use a Rails Engine?
· Do I need special hosting service to have a ROR application on the web?
· What are some tools I can use to learn ROR?
· What are some good websties about ROR?
· What port does ROR run on?
· Can I use ROR with apache?
· Can I use ROR with lighttpd?
· What are relationships?
· What is a many to many relationship?
· What is a one to many relationship?
· Where would I use a JOIN?
· How can I search and retrieve data in ROR?
· How do I insert data into databases with ROR?
· What is tagging?
· What is Web 2.0?
· How can I make text editable without reloading the page?
· How can I use AJAX to make the page not have to reload to login?
· What is JRuby?
· How do I make elements draggable?

Tags: ,

Monday, March 06, 2006

Using AJAX and Ruby on Rails to Display Alexa graphs

I have posted a new tutorial on how to use AJAX and Ruby on Rails to display Alexa traffic graphs and site rank information at Designerz Blog.


Sunday, March 05, 2006

acts_as_taggable pagination

Recently I needed to paginate the results of find_tagged_with method. I am using the acts_as_taggable plugin.

I did not want to paginate the collection after it has been retrieved since the data set I am working with is huge.

Just for reference, using the paginate_collection function, you'll use something like this to paginate your collection:

q_favorites=Favorite.find_tagged_with(:any => params[:tag], :separator=>',', :order=>'updated_at DESC')
@favorite_pages, @favorites = paginate_collection(:collection=>q_favorites, :page => @params[:page])

So, after looking around (and not finding a solution), I finally decided to go the query way.

Here's my solution based on paginate example in the Wiki. Enjoy:

page = (params[:page] ||= 1).to_i
items_per_page = 3
offset = (page - 1) * items_per_page

@webpage_count = Webpage.count("tags_webpages.tag_id = AND ( = 'Accounting' ) AND = tags_webpages.webpage_id",
joins = ", tags_webpages, tags")

@webpage_pages =, @webpage_count, items_per_page, page)

@webpages=Webpage.find_tagged_with(:any => params[:tag], :limit=>items_per_page, :offset=>offset, :separator=>',', :order=>'updated_at DESC')

If you can think of something better, please post a comment.

Friday, March 03, 2006

Travering Arrays, Hashes and Collections. [Ruby on Rails]

Traversing a hash's values

myitems.each_value do |item|
# do stuff with item

Traversing an array (similarly a collection can be traversed)

myitems.each do |key, value|
# do stuff with key and value

Tagging on Rails: acts_as_taggable count DESC

Today, while working on a project involving acts_as_taggable I noticed something interesting:

I was using something like:

@tagged_blogosphere = Webpage.tags_count(:limit => 100,:order=>' count desc ' )

and this was producing the following SQL statemetn:

SELECT AS id, AS name, COUNT(*) AS count FROM tags_webpages, webpages, tags WHERE tags_webpages.tag_id =
AND tags_webpages.webpage_id = GROUP BY ORDER BY count desc LIMIT 100

However, the records weren't really in order specified.

After a few minutes of researching I found that the order is lost when the hash is being prepared for the tags_count table.

So, following the advice mentioned on Singleton methods for acts_as_taggable page, I modified my call as follows

@tagged_blogosphere = Webpage.tags_count(:limit => 900,:raw=>true, :order=>' count desc ' )

Because of that, I had to change my display also (thanks to Tom Fakes for the tag cloud function.

<ul class="taglistinline">
<% tag_cloud(@tagged_blogosphere, %w(cloud1 cloud2 cloud3 cloud4 cloud5 cloud6 cloud7)) do |tag, cloud_class| %>
<!-- < %= link_to(h("<#{tag}>"), tag_item_url(:name => tag), { :class => cloud_class } ) -% > -->
<!-- <font style="font-size:<%= cloud_class %>"><%= tag%></font> -->

<li> <%= link_to(h("#{tag}"), "//#{url_home}/tag/"+ u("#{tag}"), { :class => cloud_class } ) %></li>

<% end %>

The default implementation of Tom Fakes' function is (WHEN NOT USING :raw=>true) :

def tag_cloud(tag_cloud, category_list)
max, min = 0, 0
tag_cloud.each_value do |count|
max = count if count > max
min = count if count < min

divisor = ((max - min) / category_list.size) + 1

tag_cloud.each do |tag, count|
yield tag, category_list[(count - min) / divisor]

If you want to use :raw=>true option, you can use the following:

def tag_cloud_raw(tag_cloud, category_list)
max, min = 0, 0
tag_cloud.each do |element|
count = element['count'].to_i
max = count if count > max
min = count if count < min

divisor = ((max - min) / category_list.size) + 1

tag_cloud.each do |element|
tag = element['name']
count = element['count'].to_i
yield tag, category_list[(count - min) / divisor]

Yahoo! User Interface Blog

earlier I posted about YUI. Here' the blog for it: Yahoo! User Interface Blog

Yahoo! UI Library

Just came across this library while reading the Ruby on Rails list and wanted to let everyone know. Yahoo! has released a wonderful library consisting of its UI tools:

Yahoo! UI Library: "The Yahoo! User Interface Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, HTML and AJAX. The UI Library Utilities facilitate the implementation of rich client-side features by enhancing and normalizing the developer's interface to important elements of the browser infrastructure (such as events, in-page HTTP requests and the DOM). The Yahoo UI Library Controls produce visual, interactive user interface elements on the page with just a few lines of code and an included CSS file. All the components in the Yahoo! User Interface Library have been released as open source under a BSD license and are free for all uses."

Also see Yahoo! Patterns

Thursday, March 02, 2006

Rails Chicklets

Here are the chicklets that I created. Enjoy.

I would appreciate a credit wherever possible.


If you like the chicklets, consider donating any amount:

Ruby on Rails with Apple

Apple has finally noticed Ruby on Rails and published a tutorial about it: Using Ruby on Rails for Web Development on Mac OS X

"The Ruby on Rails web application framework has built up a tremendous head of steam over the last year. Fueled by some significant benefits and an impressive portfolio of real-world applications already in production, Rails is destined to continue making significant inroads in 2006. Simply put, Ruby on Rails is an open source tool that gives you the advantage of rapidly creating great web applications backed by SQL databases to keep up with the speed of the web. And with the release of Rails 1.0 kicking off the new year, there's never been a better time to climb aboard."

I was going to buy Textmate but it sucks that it is available for only MAC OSX

eXTReMe Tracker