Saturday, March 27, 2010

JSON-P on Rails with jQuery

How to do render JSON-P data format on Rails, it's not complicated.. here the codes

firstly, you must render json format from your controller

def request
respond_to do |format|
format.json do
render :json => {:say => "Hello"}.to_json, :callback => params[:callback]
end
end
end

Next, you can access the json format data with ajax, exactly with jQuery

jQuery.ajax({
url:"http://127.0.0.1:3000/example/request.json?callback=?",
type:"jsonp",
method:"GET",
success:function(data)
{
console.log(data);
}
});

With jQuery ajax request make you can access the site with across domain, so you can access it from other domain.

Tuesday, March 16, 2010

Restore MBR GRUB2 on Ubuntu (live cd)

Hi guys,

One day my friend got the trouble, he is missing the boot of Linux after installed Windows...

He used Ubuntu 9.10 version it's called the "Karmic Koala", exactly on this version use the GRUB2 for MBR on them.

Here is steps to get back MBR linux and windows,

insert your "Ubuntu" CD in devices and boot from that make sore you are available on Ubuntu system now!,

open "Terminal" you can find it at Applications menu > Accessories > Terminal

firstly, you must find the partition has installed Ubuntu on your HDD, Follow these instructions:

1. sudo fdisk -l

Here is the results (it's mine)

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        3824    30716248+   7  HPFS/NTFS
/dev/sda2            3825       14593    86501992+   f  W95 Ext'd (LBA)
/dev/sda5            3825        6374    20482843+   7  HPFS/NTFS
/dev/sda6            6375        6872     4000153+  82  Linux swap / Solaris
/dev/sda7            6873       12161    42483861   83  Linux
/dev/sda8           12162       14593    19535008+  83  Linux
you can see that, on my computer Ubuntu has on "sda8" position, ok next mounting on this partition

2. sudo -i

3. mount /dev/sda8 /mnt


4. grub-install --root-directory=/mnt/ /dev/sda


Ok, next restart your system and switch on from Ubuntu boot without the live CD

for the last change type this instructions on the Terminal again.

5. sudo update-grub


that's all finish yet, hope this helpful :)

Regards,

Arul.