Your SlideShare is downloading. ×
.09The Ruby on Rails WebFrameworkTechnical ReportAnthony N. Ilukwe
3Executive SummaryOver the past three years, Ruby on Rails has become one of the most popular web applicationframeworks fo...
4Table of ContentsExecutive Summary..........................................................................................
51. IntroductionSince the early 90’s, several software frameworks have been created for the purpose ofdeveloping database ...
6In addition to its relatively compact structure and built-in features, one of the maindistinctions of RoR is the “Convent...
7• ActiveRecord• ActiveMailer• ActiveSupportFigure 1: Ruby On Rails Architecture2.1.4. Emphasis on ConventionRoR follows a...
8The creators of RoR wanted a web framework that reduced a lot of the coderedundancy often associated with other framework...
92.2.4. Built-in Web ServerRuby On Rails contains a built-in web server called WEBrick. This built-in web serverdoes not n...
103.2. Advantages of Ruby Over Other Languages• Portability• Ability to overload operators• Auto garbage-collection• Flexi...
11Prints:HelloHelloHelloHelloHello3.1.1. A More Advanced Loopputs "@@@@@"ss = 5while ss > 0puts ssss -= 2if ss == 1ss += 5...
12FordChrysler3.4.4. String MethodsBelow are examples of simple String operations, for a String defined as “Yes we can”new...
13Figure 2: Application directories and files being created with the “rails” command
14Figure 3: Directory structure of the empty Apollo application.4.1.1.1. ModelThe model folder consists of Ruby class file...
154.1.1.2. ViewThe view folder contains the interface files through which the application is viewedby users. These files a...
165. ConclusionThe ease and simplicity of Ruby On Rails makes it possible for an individual to handle a webdevelopment pro...
17ReferencesCorbridge, R., Introducing Ruby On Rails, Software Developer.http://www.softwaredeveloper.com/features/intro-t...
Upcoming SlideShare
Loading in...5
×

RubyOnRails

294

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
294
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "RubyOnRails"

  1. 1. .09The Ruby on Rails WebFrameworkTechnical ReportAnthony N. Ilukwe
  2. 2. 3Executive SummaryOver the past three years, Ruby on Rails has become one of the most popular web applicationframeworks for developers. Ruby on Rails, shortly known as RoR, has redefined the way webapplications can be created and deployed.One of its underlying principles, “Convention over configuration,” defines the developmentapproach that emphasizes clean, concise code; making RoR applications easy to understand,code, test, and debug.RoR has a series of features such as code generation, security, validation, transaction, andtesting; making it highly compact, portable, and tidy. It is also bundled with a web server,WEBRick; JavaScript library, Prototype; and AJAX library, script.aculo.us. These in-built librarieseliminate the need to import external tools, and make it easier for developers to integrate awide variety of dynamic effects into their applications.RoR is developed with the Ruby programming language.A RoR application can be created in minutes. After installing the 3 main components: Ruby,Rails (framework), and MySQL on a machine; a series of simple commands can get a basic Rubyon Rails environment up and running.
  3. 3. 4Table of ContentsExecutive Summary............................................................................................................... 31. Introduction ...................................................................................................................... 52. Ruby on Rails..................................................................................................................... 52.1 Structure................................................................................................................................ 62.1.1 Environment .................................................................................................................... 62.1.2 MVC Pattern .................................................................................................................... 62.1.3 Libraries ........................................................................................................................... 72.1.4 Emphasis on convention.................................................................................................. 82.2 Features................................................................................................................................. 82.2.1 Built-in JavaScript libraries .............................................................................................. 82.2.2 Web Services ................................................................................................................... 82.2.3 Scaffolding ....................................................................................................................... 92.2.4 Built-in web server........................................................................................................... 92.2.5 Rake ................................................................................................................................. 93. Ruby: The Language........................................................................................................... 93.1 History & Description ............................................................................................................ 93.2 Advantages of Ruby............................................................................................................. 103.3 Syntax .................................................................................................................................. 103.4 Examples of Ruby Code....................................................................................................... 103.4.1 Simple Hello Word......................................................................................................... 103.4.2 Simple Loop ................................................................................................................... 103.4.3 Arrays............................................................................................................................. 113.4.4 String Methods .............................................................................................................. 124. Inside RoR Development.................................................................................................. 124.1 The development environment .......................................................................................... 124.1.1 Creating a simple application ........................................................................................ 124.1.1.1 Model...................................................................................................................... 144.1.1.2 View......................................................................................................................... 154.1.1.3 Controller................................................................................................................ 155. Conclusion....................................................................................................................... 166. References....................................................................................................................... 17
  4. 4. 51. IntroductionSince the early 90’s, several software frameworks have been created for the purpose ofdeveloping database and interactive, or action-driven websites, or web applications.There are a number of different web application frameworks, from which developershave a wide variety to choose. These web application frameworks vary according totheir scripting languages, back-end server compatibility, configuration, structure, built-infunctionality, and supported frameworks.However, most web application frameworks have similar features such as:• Authentication• Databases• HTML or Layout directory• Libraries• Computer-to-computer interactionPopular web application frameworks include: ASP.NET, Echo, JQuery, Scheme,ColdFusion, Python, Perl, PHP, and Ruby.This report will discuss Ruby On Rails as a Ruby web application framework. It will detailthe main components, features, and structure of this framework, as well as highlightingwhy it is being embraced by a growing number of Web 2.0 developers.2. Ruby On RailsRuby On Rails (RoR) is one of a growing number of free “Open Source” web applicationframeworks available. The source code for these “Open Source” frameworks is availablefor developers to tweak, and as a result the collaborative effort is beneficial to theentire community of developers and users.RoR was first released by a team led by Danish programmer David Heinemeier-Hanssonin 2004, and several versions have been released ever since.
  5. 5. 6In addition to its relatively compact structure and built-in features, one of the maindistinctions of RoR is the “Convention over Configuration” philosophy that defines theunderlying development techniques. This will be discussed in the next section.2.1. Structure2.1.1. EnvironmentThe RoR environment runs on web servers such as WEBrick, Mongrel, and Apache.Apache is the most widely used of the aforementioned, although WEBRick and Mongrelwere initially used to run RoR.Popular open-source relational database management system MySQL is most commonlyused to provide database services for RoR applications, as it is also built for smoothfunctionality with Apache web servers. Other database systems such as Oracle andSQLite can also be used.2.1.2. MVC PatternRoR applications are structured according to the MVC (Model View Controller) softwareengineering pattern. This structural pattern ensures that the interface, application, anddatabase files are separated in a manner that especially suites agile applicationdevelopment.When a RoR application development project is initiated, the application folder iscreated with a subfolder for each of these components (model, view, and controller).2.1.3. LibrariesThere are several libraries that merge to form the RoR framework. These librariesprovide different functions in the general framework structure, such as web services,database-mapping and mail services.Some of these libraries include:• ActivePack• ActiveResource
  6. 6. 7• ActiveRecord• ActiveMailer• ActiveSupportFigure 1: Ruby On Rails Architecture2.1.4. Emphasis on ConventionRoR follows a strict naming convention, which when correctly used, easily identifiesvarious components in an application, from fields to objects and variables.Database tables have to be given names in plural, as they represent objects. And certaintable attributes have to follow a strict pattern. For example, a database table would becalled “animals,” representing an Animal object in the system, while the foreign keycolumn would be named “animal_id.”
  7. 7. 8The creators of RoR wanted a web framework that reduced a lot of the coderedundancy often associated with other frameworks like PHP and ASP. This conventionleads to concise, clever, and arguably clean lines of code that can be easily debuggedand modified.In a subsequent section, this will be discussed in more detail.2.2. Features2.2.1. Built-in JavaScript LibrariesRoR is shipped with JavaScript library or framework Prototype, which offers a variety ofclient-side dynamic effects for web applications. This bundling makes it easy fordevelopers to use Javascript commands and scripting within Rails applications, withouthaving to import – the likely case when developing with most other web frameworks.Another Javascript/AJAX library, script.aculo.us, is also bundled with RoR. LikePrototype, Script.aculo.us is useful for visual effects, and it additionally provides a rangeof user interface elements as well as more dynamic effects.2.2.2. Web ServicesRoR uses the web services SOAP and RESTful to support its computer-to-computernetwork interaction.2.2.3. ScaffoldingOne of the handiest features that RoR has to offer is scaffolding. This is a techniquethrough which code is generated for an application by simply entering thecorresponding commands.For example, the command line entry scaffold :model_name will generate aseries of Ruby files that server as a bridge between the controller and the model(database).
  8. 8. 92.2.4. Built-in Web ServerRuby On Rails contains a built-in web server called WEBrick. This built-in web serverdoes not necessarily have to be run with a local Rails application, but it serves thepurpose of creating a complete development environment within the package.2.2.5. RakeRake is a feature than enables developers to use simple pre-built commands to performtasks like database migrations, backups, and cache generation. This is one of thehandiest features of Ruby On Rails, as it enables developers to use pre-made rakecommands, and also to create their own; hence using less code and saving time.For example, if an update is made to a database schema, typing rake db:migrate willinstantly synchronize all the model files related to the updated schema. More examplesof rake will be shown later.3. Ruby: The LanguageAs stated earlier, the Ruby On Rails framework is based on the Ruby programminglanguage. The next subsections give a detailed overview of Ruby.3.1. History & DescriptionRuby was created by Japanese programmer Yukihiro Matsumoto with the goal of a cross-platform, object-oriented programming language that also incorporates proceduralprogramming techniques in addition to practices such as automatic garbage collection,memory management and code generation.Ruby was initially developed with C, and has syntax that is similar to that of Perl, Python,and SmallTalk. In another section, I will substantiate more on Ruby grammar.Unlike Java and C++, Ruby instance variables are always private and cannot be accessedwithout accessor methods. These Ruby accessor methods are a lot simpler than in Java, andsome examples are included in Section 3.4.
  9. 9. 103.2. Advantages of Ruby Over Other Languages• Portability• Ability to overload operators• Auto garbage-collection• Flexibility• Exception handling• Large standard library• Iterators and closures3.3. SyntaxOne of Ruby’s distinctive features is the somewhat intrinsic detail involved with thegrammar and syntax.Some of the major syntax rules are listed below:• Line breaks are used to signify the end of a statement• Instead of brackets, keywords are used to signify class and method definitions• Local variables must always begin with lower case characters• Constants must always begin with upper case characters• Instance variables start with @• Global variables start with $• Comment blocks start with #3.4. Examples of Ruby Code: Methods and Classes3.4.1. Simple Hello Wordprint "Hello world!"This simply prints out the text “Hello world!”3.4.2. Simple Loop#!/usr/bin/Rubyfor ss in 1...5print ss, " Hellon";end
  10. 10. 11Prints:HelloHelloHelloHelloHello3.1.1. A More Advanced Loopputs "@@@@@"ss = 5while ss > 0puts ssss -= 2if ss == 1ss += 5endPrints out:@@@@@536423.4.3. ArraysHere, I created an array and used the .each methods to loop through:cars = ["Honda", "Nissan", "Toyota", "GMC", "Ford", "Chrysler"]cars.each { |i| print i, "n"}Prints:HondaNissanToyotaGMC
  11. 11. 12FordChrysler3.4.4. String MethodsBelow are examples of simple String operations, for a String defined as “Yes we can”newstring = "Yes we can" #declare variablenewstring.capitalize # prints "Yes We Can"newstring.downcase # prints "yes we can"newstring.reverse # prints "nac ew sey"As I’ve shown in this section, Ruby is a very easy language to learn, and the similarity tocommon English makes the syntax less of a burden for beginners.4. Inside Ruby On Rails DevelopmentThis section will examine the creation of a basic Ruby On Rails application, as well as aninside look at the Ruby On Rails application environment.4.1. The development environment4.1.1. Creating a simple applicationAfter installing Ruby, Rails, and MySQL database, running the following terminalcommand inside the development directory will create an empty Ruby On Railsapplication called “Apollo.”rails apolloAs seen in the next graphic, this command creates the entire application directorystructure and a series of Ruby, HTML, and database files.
  12. 12. 13Figure 2: Application directories and files being created with the “rails” command
  13. 13. 14Figure 3: Directory structure of the empty Apollo application.4.1.1.1. ModelThe model folder consists of Ruby class files that define every domain (entity) in theapplication model. That is, for each table on the database, there is a correspondingclass in this folder. The class defines the attributes (columns) of each domain.
  14. 14. 154.1.1.2. ViewThe view folder contains the interface files through which the application is viewedby users. These files are mostly HTML files that contain slices of RHTML (embeddedRuby code) to drive the web page’s dynamics.4.1.1.3. ControllerThis folder consists of Ruby classes that communicate with the application data,based on user interaction with the view layer. These Ruby files perform a variety offunctions in order to ensure that data is being fetched from the database tables anddisplayed on the interface, when necessary.Figure 4: Model View Controller Architecture
  15. 15. 165. ConclusionThe ease and simplicity of Ruby On Rails makes it possible for an individual to handle a webdevelopment project that would have conventionally been done by a team.As web development reaches newer and greater heights; with unending potential forspeed, efficiency, and dynamism, Ruby On Rails will become a staple for some of the greatweb applications yet to come.
  16. 16. 17ReferencesCorbridge, R., Introducing Ruby On Rails, Software Developer.http://www.softwaredeveloper.com/features/intro-to-Ruby-on-rails-part-two-043007. 2007.Introducing Ruby On Rails. The Workshop.http://www.eclips3media.com/workshop/2007/06/28/introducing-Ruby-on-rails.2007.Ruby On Rails. (2009, January 12). In Wikipedia, the free encyclopedia. RetrievedJanuary 17, 2009, from http://en.wikipedia.org/wiki/Ruby_on_RailsRuby (Programming Language). (2009, January 3). In Wikipedia, the freeencyclopedia. Retrieved January 8, 2009, fromhttp://en.wikipedia.org/wiki/Ruby_(programming_language)

×