Server Side - SoftwareEngineeringOnline.com

quaggahooliganInternet and Web Development

Feb 5, 2013 (4 years and 6 months ago)

122 views

Ruby on Rails

By



Adam Alford

Anant Pradhan

Brooks Folk

Introduction


Ruby on Rails is an open source, free web application framework.




Aims to increase the speed and ease with which database
-
driven
web sites can be created




Offers skeleton code frameworks (scaffolding) from the outset.




Applications using the Rails framework are developed using the
Model
-
View
-
Controller design paradigm

History


Ruby on Rails was developed and released in 2004 by David
Heinemeier Hansson, a developer at 37Signals.




Various major releases, starting with the stable 1.0 release in
December of 2005 and a major update in version 1.1 released in
March of 2006.




Over time, Rails has incorporated AJAX built in functionalities.




Enables the developer to build robust web applications faster, using
less code than other platforms.

Applications


Ideal solution for Web
-
based applications that require database
connections.




Doesn’t require any configuration files, except for a database
configuration file.




Basecamp

is the original Ruby on Rails application from which the
framework was extracted.




Another example of a very popular web application built using Ruby
on Rails is
Backpack
.

Sample Code

## This class gives the difference between 2 dates in years, months, and days


class Date


def distance_to(end_date)


years = end_date.year
-

year


months = end_date.month
-

month


days = end_date.day
-

day


if days < 0


days += 30


months
-
= 1


end


if months < 0


months += 12


years
-
= 1


end


{:years => years, :months => months, :days => days}


end

end

Sample Code

## This class creates a country table

class CreateCountryTable < ActiveRecord::Migration


def self.up


create_table :countries do |t|


t.column :iso, :string, :size => 2


t.column :name, :string, :size => 80


t.column :printable_name, :string, :size => 80


t.column :iso3, :string, :size => 3


t.column :numcode, :integer


end


Country.reset_column_information


Country.create(:iso => 'AF', :name => 'AFGHANISTAN', :printable_name =>
'Afghanistan', :iso3 => 'AFG', :numcode => '004')


Country.create(:iso => 'AL', :name => 'ALBANIA', :printable_name => 'Albania', :iso3
=> 'ALB', :numcode => '008')


Country.create(:iso => 'DZ', :name => 'ALGERIA', :printable_name => 'Algeria', :iso3
=> 'DZA', :numcode => '012')


Country.create(:iso => 'AU', :name => 'AUSTRALIA', :printable_name => 'Australia',
:iso3 => 'AUS', :numcode => '036')


end


def self.down


drop_table :countries


end

end

Development Environments


RadRails
: A Rapid Application Development IDE for the Ruby on Rails
framework. Built on the Eclipse IDE.


Free and open source; cross
-
platform, stand
-
alone IDE or Eclipse
plug
-
in


Embedded database navigator and query console


Fast, integrated debugger


Syntax highlighting, auto completion, code assist, error reporting,
outlining, etc.


Unified, deep support for Ruby, Rails, RHTML, JS, HTML and CSS.




TextMate
: TextMate is a general
-
purpose GUI text editor for Mac OS X.
Features:


Tabs


Recordable macros


Folding sections and snippets


Shell integration


Extensible bundle system, all built around its novel scope system.

Client
-
side or Server
-
side


Ruby on Rails is a
Server Side

scripting language /
framework.





Such languages don't have a compiler or a compilation
phase per se, instead, they use an interpreter
--

a
program that runs on the web server
--

to translate hand
-
written code into machine
-
executable code on the fly.

References


http://www.regdeveloper.co.uk/2006/07/03/ruby_rails_part1/


http://www.rubyonrails.org/applications


http://www.rubyonrails.org/


http://www.rubyinside.com/21
-
useful
-
ruby
-
and
-
rails
-
code
-
snippets
-
24.html


http://en.wikipedia.org/wiki/Ruby_on_Rails


http://swik.net/Rails


http://ifakedit.com/log/2006/01/17/best
-
ideeditor
-
for
-
ruby
-
on
-
rails/


http://www.aptana.com/rails


http://macromates.com/


http://en.wikipedia.org/wiki/RadRails


http://en.wikipedia.org/wiki/TextMate