Thursday, November 5, 2009

Googlemap show Directions between two places

Place the below js code in head tag
var map;
var directionsPanel;
var directions;
function initialize() {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(42.351505,-71.094455),12);
directionsPanel = document.getElementById("route");
directions = new GDirections(map, directionsPanel);
directions.load("from:kakinada,india to:Kurnool,india");
Place the two divs in html body with ids map_convas, route
Call onload="initialize()" onunload="GUnload()" in body tag.
directions.load("from:kakinada,india to:Kurnool,india");
here you you can also place lat,long pairs in place of from and two address

Some usefull sites for Ruby on Rails newbies

study all activerecord, actionview and actioncontroller classes
Ex: classes -> active record::call backs
which explains what action done before or after creating a record in database or before deleting a record from one table what needs to done in other tables etc

Ruby hashes. Means associatinve arrays in php. Each values is associated with one key like $array=new array(‘color’ => ‘whilte’ , ‘Height’ => ‘6 feet’)

Validation classes and lot more
All methods and available for active record like save update delete etc

Find Some things to look at

Rails ajax (Implementing remote call is very easy in RoR)

Link_to_remote with passing textbox value as a parameter


Check username availablility



Ruby on Rails Easy Deployment

Actually Ruby on Rails deployment is little bit tricky compare to PHP. PHP programs tend to require less memory to run so they tend to be easier to deploy. With the release of mod_rails and Ruby Enterprise Edition Rails becomes easier to deploy than PHP once the initial Apache add-ons are made. See from below site for full details

Pagination gem for Ruby on Rails

For ruby on rails there is a gem available for pagination called will_paginate to provide pagination to the database results. Process to install this gem to your application.
1. rake gems:install
2. gem sources -a
3. gem install mislav-will_paginate
For the first time to install gems package run step 1. If you already run this command no need to run again. step 2 is to append the gems to your rails. Step 3 will install the will_paginate gem to your application.

After installed gem successfully follow the below steps to enable pagination to your models.

1. In your config\environment.rb file add do |config|
config.gem 'mislav-will_paginate', :version => '~> 2.2.3', :lib => 'will_paginate', :source => ''

2. rake gems:install

3. In your model, mention how many records display per page

def self.per_page

4. In your controller, replace
@yourmodels = Yourmodel.find
@yourmodels = Yourmodel.paginate :page => params[:page], :order => 'created_at DESC'
5. In your index view, add below to see the pagination
<%= will_paginate @models %>

see http://localhost:3000/models