Ruby On Rails Introduction - PowerPoint PPT Presentation

1 / 36
About This Presentation
Title:

Ruby On Rails Introduction

Description:

The convention used makes working on projects with multiple coders easier ... This allows you to write code in a controlled manner along with other coders ... – PowerPoint PPT presentation

Number of Views:110
Avg rating:3.0/5.0
Slides: 37
Provided by: Office20093
Category:

less

Transcript and Presenter's Notes

Title: Ruby On Rails Introduction


1
Ruby On Rails Introduction
2
What is Ruby On Rails (RoR)?
  • Its a free web application framework
  • It is based on the Ruby language
  • It allows for web projects to be developed
    quickly, simply and efficiently

3
RoR History
  • Came from web based project management software
    (Basecamp)

4
RoR History II
  • Extracted by David Hansson of 37Signals
  • Basecamp allowed a centralised approach to
    project management software
  • Basecamp comes with an API for integration into
    other software
  • It was a simple way of managing projects project
    flow, milestones, to-do lists etc
  • RoR went public in 2004
  • In 2007 apple shipped OSX (Leopard) with RoR

5
RoR philosophy
  • RoR was designed to make life as simple as
    possible
  • This increases productivity
  • Reduces initial learn time
  • Makes managing, debugging easier
  • The convention used makes working on projects
    with multiple coders easier
  • Less decisions need to be made because of this
    convention

6
What is Ruby?
  • Ruby is the language that RoR is based on
  • It is purely object orientated
  • Originated in Japan in the 90s

7
What is Rails?
  • It is a framework for the Ruby language
  • It is designed for web based applications with a
    database back-end
  • These are very common in the WWW
  • Are becoming more popular

8
Why is this technology so popular?
  • Standalone software is decreasing in popularity
  • Centralisation of software makes sense
  • Distribution can be controlled easily when
    centralised
  • User access can be controlled
  • Updating of software becomes much easier

9
Software Centralisation
  • Can give cheaper per unit costs
  • Reduction in the administration of software
  • Support costs adhere to economies of scale
  • The more people using the software means that the
    costs per user reduces

10
Installation
  • RoR has been a pain to install in older years
  • Especially true on OSX
  • Easy now that OSX comes with preinstalled
  • For Win users there is an all in one installer
    for Ruby http//rubyinstaller.rubyforge.org/

11
Win Installation
12
The development family
  • Various tools are used to develop RoR
    applications
  • These include
  • Ruby
  • Rails
  • MySQL, SQLite3.
  • Mongrel
  • Capistrano
  • Subversion
  • Each of these has its own subsets of tools

13
MySQL
  • We have already mentioned MySQL for databases
  • This is a good choice for RoR and its free!
  • This needs to be installed and set up
  • Download some tools which allow you to
    graphically manipulate your databases. Its
    easier!!

14
MySQL GUIs
  • For windows you can use the Control Center
  • For OSX you can use CocoaMySQL
  • You can make a web/server based GUI such as
    PHPmyAdmin. You may have seen and used this on
    the University server http//www.cs.cf.ac.uk/phpMy
    Admin/

15
Mongrel
  • Mongrel is the server that RoR uses
  • Or rather that the Ruby web apps use
  • Uses HTTP for its serving. We should remember
    this protocol from before!
  • Not based on Common Gateway Interface (CGI) which
    can be used to interface with applications for
    the web

16
Capistrano
  • Capistrano can be used to deploy your RoR
    application
  • It was originally called SwitchTower
  • It allows you to execute commands over multiple
    servers.
  • It is dynamic so can interact with the output
    from servers

17
Subversion
  • Subversion is a Version Control System
  • This allows you to write code in a controlled
    manner along with other coders
  • Code can be rolled back if necessary
  • All updates to the code are time stamped and
    commented
  • The only way for multiple coders to work on the
    same project

18
RoR
  • RoR is based on 2 main principles
  • Content over Configuration
  • Dont repeat yourself

19
Content over Configuration
  • "Convention over Configuration" means a developer
    only needs to specify unconventional aspects of
    the application. For example, if there's a class
    Sale in the model, the corresponding table in the
    database is called sales by default.
  • It is only if one deviates from this convention,
    such as calling the table "products_sold", that
    one needs to write code regarding these names.
    Wikipedia

20
Dont repeat yourself
  • Don't Repeat Yourself (DRY, also known as Single
    Point of Truth) is a process philosophy aimed at
    reducing duplication, particularly in computing.
  • The philosophy emphasizes that information should
    not be duplicated, because duplication increases
    the difficulty of change, may decrease clarity,
    and leads to opportunities for inconsistency.
    Wikipedia

21
Model-View-Controller (MVC)
  • The Rails framework uses the MVC architecture
  • Use of the MVC architecture should keep the
    Business Logic and the User Interface seperated
    to an extent
  • This allows one to be altered or updates without
    affecting the other

22
Business Logic
  • This is the way that databases interact with the
    User Interface
  • They control how data is gathered, manipulated
    and passed about
  • They are in essence the algorithms which do the
    clever bits with the data (if there are any!)

23
The MVC Model
  • The business logic just mentioned is a part of
    the Model
  • Along with this is the data that it interacts with

24
The MVC Diagram
25
The MVC View
  • The view is geared at the User Interface
  • This can be the text on the page
  • Your input devices such as text boxes etc

26
The MVC Controller
  • This interfaces between the model and the view
  • It lets the model know what the user is doing in
    the view
  • This can be user input from the mouse or the
    keyboard

27
MVC for web applications
  • Model - The data in the database and the
    algorithms used to manipulate it
  • View - The front end HTML pages
  • Controller - Gathers the data based on user input
    thats used as content for the HTML

28
The MVC Cycle
  • The user interacts with the user interface in
    some way (e.g. presses a button).
  • A controller handles the input event from the
    user interface, often via a registered handler or
    callback.
  • The controller notifies the model of the user
    action, possibly resulting in a change in the
    model's state. (e.g. controller updates user's
    Shopping cart).
  • A view uses the model (indirectly) to generate an
    appropriate user interface (e.g. the view
    produces a screen listing the shopping cart
    contents). The view gets its own data from the
    model. The model has no direct knowledge of the
    view.
  • The user interface waits for further user
    interactions, which begins the cycle anew.
    Wikipedia

29
Scaffolding
  • In RoR scaffolding helps speed up development of
    the connectivity between the database and the
    user interface
  • It provides a basic set up from which you can
    build your application
  • Called scaffolding because as you build up your
    app you remove the scaffolding (akin to house
    building!)
  • It can create all of the read, write, delete etc
    code and associated front end for database apps.
    We will see this later
  • In the MVC this will create the models and views
    that we need to get started

30
Rake
  • This is a ruby specific make tool
  • If you have programmed in other languages you may
    have used make before
  • Used extensively in C coding
  • If you have many files in a project then when
    compiling there is only the need to recompile
    files that have changed and their dependants
  • Make does this
  • Rake is a similar tool for building ruby code
  • Uses Rakefiles to control how it works

31
A simple application
32
Scaffolding
  • This simple example is created using the RoR
    scaffolding
  • Remember this is the basics of a project for you
    to build from

33
How does it work?
  • The show hyperlink
  • When clicked this executes ruby code
  • The hyperlink points to http//localhost3000/even
    ts/1
  • The link issues a GET request for the event at
    that address
  • This is how the appropriate ruby code gets
    executed
  • This is all based on conventions making
    development for us quicker as all the code can be
    generated for us

34
Controller
  • This GET request for that particular event fires
    the controller
  • This is how the front end communicates with the
    database and business logic
  • This will go and get the necessary data from the
    database to display on the HTML page for show

35
Views
  • We have now fetched the data that we need from
    the database
  • And the ruby code found in the app/views part of
    our application lets us create the HTML

36
Creating HTML
  • ltpgt
  • ltbgtNamelt/bgt
  • lt h _at_event.name gtlt/pgt
  • ltpgt
  • ltbgtBudgetlt/bgt
  • lt h _at_event.budget gt
  • lt/pgt
  • lt link_to 'Edit', edit_event_path(_at_event)
  • lt link_to 'Back', events_path gt

Retrieved database data
Ruby code
Create URLS based on naming conventions
Write a Comment
User Comments (0)
About PowerShow.com