Friday, November 6, 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

From http://api.rubyonrails.org/
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’)
http://www.rubyonrailsexamples.com/category/ruby-hash/

Validation classes and lot more
http://apidock.com/rails/ActiveRecord/Validations/ClassMethods
http://apidock.com/rails/ActiveRecord/Base
All methods and available for active record like save update delete etc
*********************************

Find Some things to look at
http://www.palmcoder.net/?p=265

Tutorials
Rails ajax (Implementing remote call is very easy in RoR)
http://onlamp.com/onlamp/2005/06/09/rails_ajax.html

Link_to_remote with passing textbox value as a parameter
http://onlamp.com/onlamp/2005/06/09/rails_ajax.html

Forum

http://railsforum.com

Check username availablility
http://railsforum.com/viewtopic.php?id=22828

Gems
http://ariejan.net/gems/

http://www.digitalmediaminute.com/article/1816/top-ruby-on-rails-tutorials

Testing
http://www.tutorialspoint.com/ruby-on-rails-2.1/rails-unit-testing.htm

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
http://b.lesseverything.com/2008/8/25/comparing-php-to-ruby-on-rails

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 http://gems.github.com
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.

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

1. In your config\environment.rb file add
Rails::initializer.run do |config|
config.gem 'mislav-will_paginate', :version => '~> 2.2.3', :lib => 'will_paginate', :source => 'http://gems.github.com'
end


2. rake gems:install

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

def self.per_page
5
end

4. In your controller, replace
@yourmodels = Yourmodel.find
with
@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
-----------------------End-------------------------------------------