1 / 47

Ruby On Rails

Ruby On Rails. Irma & Robert. Ruby On Rails. Irma & Robert. What is Ruby On Rails ?. Ruby on Rails is an open source web application framework for the Ruby programming language. It is often referred to as "Rails" or "RoR".

Download Presentation

Ruby On Rails

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ruby On Rails Irma & Robert

  2. Ruby On Rails Irma & Robert

  3. What is Ruby On Rails? • Ruby on Rails is an open source web application framework for the Ruby programming language. It is often referred to as "Rails" or "RoR". • It is intended to be used with an Agile development methodology, which is often utilized by web developers for its suitability for short, client-driven projects.

  4. History on Ruby On Rails? • Ruby on Rails was created by David Heinemeier Hansson from his work on Basecamp, a project management tool by 37signals (now a web application company). • Heinemeier Hansson first released Rails as open source in July 2004, but did not share commit rights to the project until February 2005.

  5. Technical overview onRuby On Rails. • In August 2006 the framework reached a milestone when Apple announced that it would ship Ruby on Rails with Mac OS X v10.5 "Leopard", which was released in October 2007. • Like many contemporary web frameworks, Rails uses the Model-View-Controller (MVC) architecture pattern to organize application programming. Ruby on Rails features several tools intended to make commonplace development tasks easier "out of the box".

  6. Technical overview onRuby On Rails. • Rails provides scaffolding which can automatically construct some of the models and views needed for a basic website. A simple ruby web server (WEBrick) and Rake build system are also included. By including these common tools with the Rails framework, a basic development environment is in effect provided with all versions of the software.

  7. Technical overview onRuby On Rails. • Ruby on Rails relies on a web server to run it. Mongrel is generally preferred over WEBrick ,but it can also be run by Lighttpd, Apache with CGI (or FastCGI, mod ruby), and many others. Rails is also noteworthy for its extensive use of JavaScript libraries Prototype and Script.aculo.us for Ajax.

  8. Technical overview onRuby On Rails. • Rails initially utilized lightweight SOAP(Simple Object Access Protocol) for web services; this was later replaced by RESTful web services. • Since version 2.0, Ruby on Rails by default offers both HTML and XML as output formats. The latter is the facility for RESTful web services.

  9. Technical overview onRuby On Rails. • Ruby on Rails is separated into various packages, namely ActiveRecord (an object-relational mapping system for database access), ActiveResource (provides web services), ActionPack, ActiveSupport,ActiveView and ActionMailer. Prior to version 2.0, Rails also included the Action Web Service package which is now replaced by Active Resource. Apart from standard packages, developers can make plug-ins to extend existing packages.

  10. Philosophy and Design • Ruby on Rails is intended to emphasize Convention over Configuration (CoC), and the rapid development principle of Don't repeat yourself (DRY). • "Convention over Configuration" means a developer only needs to specify unconventional aspects of the application.

  11. Philosophy and Design • "Don't repeat yourself" means that information is located in a single, unambiguous place. • For example, using the ActiveRecord module of Rails, the developer does not need to specify database column names in class definitions. • Instead, Ruby on Rails can retrieve this information from the database.

  12. Recent Developments • Rails version 2.2 was released on November 21st, 2008 . The most notable features specified in 2.2 are an internationalization framework, thread safety, easy access to HTTP cashing, compatibility with Ruby 1.9 and JRuby, and new documentation. • Users can utilize the most recent unreleased versions, known as Edge Rails. • These users are typically more advanced, and are willing to deal with an unstable architecture for access to additional features.

  13. Installation of RoR • The first step is to visit the Ruby On Rails Org. to download the newest revision.

  14. Installation of RoR • There are some items that must be configured before Ruby is installed. Make sure that any and all application that are using port 80 are turn off. The most likely services are IIS, Apache and MySQL need to be disable or turn off. • This is a simple task go to the systems files in the Settings, Control Panel, Administrative Tools, Services and pick the appropriate application. Right click the service and turn off or disable.

  15. Installation of RoR • I downloaded the files to the program files and saved in the Ruby On Rails folder.

  16. Installation of RoR

  17. Installation of RoR

  18. Learning Ruby • Ruby is a web frame work which is a set of libraries. • Ruby is a scripting language that can be control by command line or XHTML. • Ruby is dynamic typing that allows for changes on a variable during run time. Ruby does not care what type of data it maybe. It will interpret any thing.

  19. Learning Ruby • The first lesson is to use command line. I made a shortcut for Ruby on the desktop. Click the icon.

  20. Learning Ruby • Once the icon is click the instant Rails window will appear.

  21. Learning Ruby • Next click the I and chose the Rails Applications, open Ruby Console Window.

  22. Learning Ruby • Then the command prompt will appear.

  23. Learning Ruby • First type IRB and from this point it will be all cmd line instructions.

  24. Learning Ruby • puts "Welcome to Ruby on Rails"

  25. Learning Ruby • myvar = 5.7 • puts "the value of myvar is #{myvar}" • myvar = myvar.round • puts "the value of myvar is rounded #{myvar}" • myvar = 5.4 • puts "the value of myvar is #{myvar}" • myvar.round • puts "the rounded vaue of myvar #{myvar}"

  26. Learning Ruby • fruits = ["mango", "orange","apple","pear"] • puts "The length of the fruits array is #{fruits.length}" • puts "The first fruit is #{fruits[0]}" • puts "The first fruit is #{fruits[-1]}" • fruits.reverse! • puts "The first fruit is #{fruits.length}" • puts "The first fruit is #{fruits[0]}" • puts "The first fruit is #{fruits[-1]}" • food = {"mango" => "fruits", "banana" => "fruit", "onion" => "vegetable"} • puts "The first fruit is #{food["mango"]}" • puts "The first fruit is #{food["onion"]}"

  27. Learning Ruby • class Point • @@num_points = 0 • def initialize(x,y) • @x = x • @y = y • @@num_points +=1 • end • def to_s • return "x #{@x}; y: #{@y}" • end • def num_points • return @@num_points • end • end • p = Point.new(8,9) • q = Point.new(1,1) • puts "the value of p is '#{p}'" • puts "the value of q is '#{q}'" • puts "the number of points created is #{p.num_points}"

  28. Learning Ruby • Ruby on Rails has two classes, ActionController and ActionView, that work together to process a client request and render a view. • To generate a controller in Rails, you can use the built-in Controllergenerator by typing ruby script/generate controllername. • A Ruby on Rails application must be run from a web server • Instant Rails comes with a built-in web server named Mongrel, which is easy to use to test Rails applications on the local machine.

  29. Learning Ruby To make the controller in Ruby you use the built in Controller Generator. First go to the file where you will put the controller then type ruby script/generate controller Name of controller class Testa2aController < ApplicationController def index render :text => "Welcome to the test file !" end end

  30. Ruby On Rails

  31. Embedded Ruby • Ruby provides a program called ERb (Embedded Ruby) • Allows to put Ruby code inside HTML file • You need to know only two things to prepare an ERb document: • to execute Ruby code, enclose it between <% and %> • to get the result of the code execution to be printed out, as part of the output, enclose the code between <%= and %> • Here is an example, the code is saved in demo.rb file. Run the program using the command line utility erb

  32. Ruby on Rails Directory Structure • when you use the RAILS helper script to create your application, it creates the entire directory structure for the application. • Except for minor changes between releases, every Rails project will have the same structure, with the same naming conventions

  33. Purpose of each directory • app : organizes application components. It’s got subdirectories that hold the view, controller and models • components: holds components tiny self-contained applications that bundle model, view and controller • config: contains small amount of configuration code that the application will need • db: you can manage the relational database with scripts you create and place in this directory • doc: this directory holds all the RubyDoc-generated Rails and application documentation • lib: you’ll put libraries here, unless explicitly belong elsewhere • log: errors logs go here • public: has web files that don’t change, such as JavaScript files (public/javascript), graphics ( public/images), stylesheets (public/ stylesheets) ad HTML files (public).

  34. Purpose of each directory • script: holds scripts to launch and manage the various tools that you’ll use with Rails • test: the tests you write and those Rails create for you • tmp: Rails uses this directory to hold temporary files for intermediate processing • vendor: libraries provided by third-party vendors • Apart from these directories there will be two files available in your project directory: • README: this file contains a basic detail about Rails Application and description of the directory structure explained above • Rakefile: this file is similar to Unix Makefile which helps with building, packaging and testing the Rails code. This will be used by rake utility supplied along with Ruby installation

  35. Creating a rails Application Workflow for creating Rails applications • use the RAILS command to create the basic skeleton of the application • create the database on the MySQL server to hold your data • configure the application to know where your database is located and the login credentials for it • create Rails Active Records (Models) because they are the business objects you’ll be working with in your application • generate Migrations that makes creating and maintaining the database tables and columns easy • write Controller Code to put a life in your application • create Views to present your data through User Interface Lets start with creating our library application

  36. Creating an Empty Rails web Application • Go to Locomotive and create the application • This will create a subdirectory for the library application containing a complete directory tree of folders and files for an empty Rails application.

  37. Creating an Empty Rails web Application • Start the server. This application runs on port 3012 • Now open your browser and go to • http://localhost:3012

  38. Rails Database Setup • Configuring database.yml • \library\config subdirectory of the Rails Application you created. • This file has the configuration section for Mysql databases. • Create the databases using MySQL Administrator

  39. Creating Active Record Files • Create the Active Record Files for our entities for library application, issue the following command from the top level of the application directory • When you use the generate tool, Rails creates the actual model file that holds all the methods unique to the model and the rules you define • Apart from creating many other files and directories, this will create files named book.rb and subject.rb

  40. Creating Active Record Files • When you have more than one model in your Rails Application, you would need to create connection between those models. • Indicate these associations by adding declarations to your models • modify book.rb and subject.rb • the implementation of validations is done in a Rails model • modify book.rb

  41. Rails Migrations • Rails Migrations allows you to use ruby to define changes to your database schema, making it possible to use version control system to keep things synchronized with the actual code • Create the Migrations: • Notice that here you are using lower case for book and subject and using the plural form while creating migrations

  42. Rails Migrations • Edit the code to tell it what to do: • go to db/migrate subdirectory and edit each file • modify 001_boks.rb • modify 002_subjects.rb

  43. Rails Migrations • Run the migration • to do this go to terminal, go to the application directory and run the rake command • This will create a "schema_info" table if it doesn't exist which tracks the current version of the database - each new migration will be a new version, and any new migrations will be run until your database is at the current version.

  44. Rails Controller – Action Controller • The Rails controller is the logical center of your application. It coordinates the interaction between the user, the views, and the model. • We will create just one controller here: • let's define few method stubs in book_controller.rb.

  45. Rails Controller – Action Controller

  46. Rails Views – ActionView • Creating view file for LIST method • create and edit a file called list.rhtml • Creating view file for NEW method • create and edit a file called new.rhtml • Creating view file for SHOW method • create and edit a file called show.rhtml • Creating view file for EDIT method • create and edit a file called edit.rhtml • Creating view file for DELETE method • you do not need to write any view code for delete method • modify list.rhtml • Creating view file for SHOW_SUBJECTS method • create and edit a file called show_subjecs.rhtml in the app/views/book directory

  47. http://www.youtube.com/watch?v=IdM_rgDaVM0

More Related