2009
01.25

Ruby on Rails: ActiveRecord to_xml – for REST API use

By Satish Natarajan

If you are going to use REST API in any fashion. You got to read this documentation

http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html

2009
01.25

Please refer to this link: http://nubyonrails.com/articles/memcached-basics-for-rails

Will add sample shortly

2009
01.24

Ruby on Rails: Merge 2 arrays – very simple c = a | b

By Satish Natarajan

Yes, That is it!

c = a | b

Union function

2009
01.24

Rails 1.2 supports Enumerable module on arrays. Here is the complete documentation: http://api.rubyonrails.org/classes/Enumerable.html. I found it very useful in say calculating sum of all the values within an array of records.

eg:

invoices = Invoice.find(:all, :conditions => “due_date < CURRENT_DATE”)

total = invoices.sum(&:amount) – VERY NICE!

2009
01.23

I looked at various lightboxes and figured out this one works the best.

http://code.google.com/p/rb-lightbox-plugin/

There is no explicit documentation – However look at the lib/lightbox-helper code for all that you needs.

The one that I like the best is the ability to do

<%= link_to_remote_lightbox “LINK NAME”, :url => link_path -%>

this loads the content within the lightbox using an ajax call dynamically.

Best results if you can create a specific layout say “Modal”

<div class=”modal”>
<div style=”float:right”><%= link_to_close_lightbox image_tag(”lightbox_close.gif”, :border=> 0)%></div>
<%= yield %>
</div>

Make sure to use this in your controller

respond_to do |wants|
wants.html
wants.js {render :layout => “modal”}
end

If you need more explanation – Please leave a comment – I will add additional documentation to this post.

BTW, I had to copy the javascript, images and stylesheets to the appropriate directory manually – was not too hard.

Also, you might have to svn checkout into the plugins directory – the script/plugin install did not work for me.

It is worth the effort.

2009
01.23

If you want to quickly see your data using scaffolding, then ActiveScaffold is your friend.

Visit ActiveScaffold here: http://activescaffold.com/

You will find it useful in writing the administration portions of the website. There are quite a bit of customizations for the creative designer!

2009
01.23

Ruby on rails remove the underline from the link
link_to(model.name, model_path(model),:style => “text-decoration: none”)

2009
01.21

Ruby on Rails: Lightbox

By Satish Natarajan

This is a good plugin to use for lightboxes.

http://www.craigambrose.com/projects/redbox

Install:  script/plugin install svn://rubyforge.org/var/svn/ambroseplugins/redbox

Initialize: cd vendor/plugins/redbox; rake update_scripts

(gave me an error) so I did

cp javascripts/* ../../../public/

cp images/* ../../../public/images/.

cp images/* ../../../public/images/.

Location with some good examples: http://richtextblog.blogspot.com/2007/09/redbox-rules.html

2009
01.21

Linux: Installing mbstring in Fedora

By Satish Natarajan

Simple ;-)

sudo yum install php-mbstring

2009
01.20

Ruby on Rails: YUI+Rails Dynamic dialog boxes

By Satish Natarajan

This is an excellent article.

http://enleitened.com/2008/06/26/dynamic-dialogs-with-rails-and-yui/