Monday, January 26, 2009

Merb gets merged into Rails 3.0 !!

Ruby on Rails team broke the news: the alternative Ruby web application framework, Merb, will be merged into Ruby on Rails 3.0.

Merb, which was already closely patterned after Rails, brings performance, modularity, and better integration with alternative JavaScript and ORM frameworks to the table. The default Rails configuration will still be the "full stack" framework, which uses ActiveRecord and Prototype, but there will also be a "Rails Core" with the ability to opt into specific other (e.g. JavaScript or ORM) frameworks as desired.

The Merb team will be working with the Rails core team on a joint project. The plan is to merge in the things that made Merb different. This will make it possible to use Rails 3 for the same sorts of use-cases that were compelling for Merb users. Effectively, Merb 2 is Rails 3.

You can read more about here:

Saturday, January 24, 2009

Inline file upload - iframe - ajax - Ruby on Rails

In View

<% form_for(@images, :url => formatted_images_path(:format => 'js'), :html => { :multipart => true,:target => 'upload_frame' }) do |f| %>
Image
<%= f.file_field :uploaded_data, :size => "50" %>
<%= f.submit :Submit %>
<% end %>
< id="'upload_frame'," name="upload_frame" style="width:1px;height:1px;border:0px" src = "about:blank">

in controller
def create
@image = Image.new
if @image.save
respond_to do |format|
format.js do
responds_to_parent do
render :update do |page|
page.replace_html 'imgupload', :partial => 'imageupload',:object => @images
page.visual_effect :highlight, "image_#{@image.id}"
end
end
end
end
end
end

Watermarking an image in Rails - Rmagick

class Image < ActiveRecord::Base

require 'RMagick'
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 4.megabytes,
:resize_to => '640x400>',
:thumbnails => { :thumb => '100x100>',:medium => '250x150' }

validates_as_attachment

def watermark_image
dst = Magick::Image.read("#{RAILS_ROOT}/public/#{self.public_filename}").first
src = Magick::Image.read("#{RAILS_ROOT}/public/images/logo.gif").first
result = dst.composite(src, Magick::CenterGravity, Magick::HardLightCompositeOp)
result.write("#{RAILS_ROOT}/public/#{self.public_filename}")
end

Improving Rails Applications performance

I have done some research about improving Rails Applications performance. I would feel the the following few points need to be considered when we optimize rails applications for performance:

1) Avoid the use of dynamic URL generation (link_to, url_for) since rails needs to look up the routes table and that may take time. Just hard code the controller name and the action.

2) Try to avoid the excess use of helpers since it adds overhead.

3) You may consider to use Rails Bench to do some testing for you rails application performance.

4) You may consider to use memcached to cache your model and library computation results.

5) try to optimize your database queries. If you use ActiveRecord find, be careful from computation intensive sql queries that returns to you a lot of data that you may not need. The method find may run many select statements for you.

Contact Me for any help regarding rails/nodejs/php/mysql

Name

Email *

Message *