1 An Introduction to the Development of Web Applications using Ruby on Rails with Ajax Ansgar Berhorn, B.Sc. and Mike Rowe, Ph.D.

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Advertisements

PHP I.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Apache Struts Technology
Chapter 15 © 2010 by Addison Wesley Longman, Inc Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in Use spread rapidly.
.NET Database Technologies: Open-Source Frameworks.
Web Applications Development Using Coldbox Platform Eddie Johnston.
Sakai on Rails Integrating Ruby and Sakai David Adams, Virginia Tech.
Introduction to Model-View-Controller (MVC) Web Programming with TurboGears Leif Oppermann,
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
Ruby on Rails by Manik Juneja Ruby On Rails. Ruby on Rails by Manik Juneja Rails is a Web Application development framework. Based on the MVC pattern.
1 Chapter 12 Working With Access 2000 on the Internet.
Software Architecture Patterns (2). what is architecture? (recap) o an overall blueprint/model describing the structures and properties of a "system"
1 Java Server Pages Can web pages be created specially for each user? What part does Java play?
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Web Programming Language Dr. Ken Cosh Week 1 (Introduction)
UNIT-V The MVC architecture and Struts Framework.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
| Lugano, Ruby on Rails.
A little engineering on Rails Robert W. Hasker. Goals Intro to the Rails framework ▫Basic concepts: MVC, Active Record ▫A bit of Ruby Using Rails to build.
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Ruby on Rails CSCI 6314 David Gaspar Jennifer Garcia Avila.
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 33 CGI Technology for Dynamic Web Documents There are two alternative forms of retrieving web documents. Instead of retrieving static HTML documents,
Web Application Programming Carol Wolf Computer Science.
Programming the Web Web = Computer Network + Hypertext.
MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
1 Approaches for Asynchronous Communication in Web Applications Stefan Potthast and Mike Rowe.
HTML. Principle of Programming  Interface with PC 2 English Japanese Chinese Machine Code Compiler / Interpreter C++ Perl Assembler Machine Code.
The Web Architecture and ASP.NET. Slide 2 Review of the Web (1) It began with HTTP and HTML, which delivers static Web pages to browsers which would render.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Web Programming Brian Toone 8/27/2014. Outline for today 1.Understanding the architecture of the web 2.Overview of programming languages – Client-side.
Google App Engine Data Store ae-10-datastore
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
ASP (Active Server Pages) by Bülent & Resul. Presentation Outline Introduction What is an ASP file? How does ASP work? What can ASP do? Differences Between.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
SERVER-SIDE WEB DEVELOPMENT.  Refers to software development for applications in which the majority of processing occurs on one or more servers (and.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
Apache Struts Technology A MVC Framework for Java Web Applications.
Fall 2000C.Watters1 World Wide Web and E-Commerce Servers & Server Side Processing.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
AJAX.
AJAX.
PHP / MySQL Introduction
Ruby on Rails by Manik Juneja
Ruby on Rails by Manik Juneja
Web Application Architectures
Chapter 15 Introduction to Rails.
Developing a Model-View-Controller Component for Joomla Part 3
Web Application Architectures
Introduction to AJAX and JSON
Web Application Architectures
Presentation transcript:

1 An Introduction to the Development of Web Applications using Ruby on Rails with Ajax Ansgar Berhorn, B.Sc. and Mike Rowe, Ph.D.

2 Contact Information Ansgar Berhorn, B.Sc. Dept. of Computer Science University of Applied Sciences / Hochschule Darmstadt Haardtring Darmstadt, Germany Michael Rowe, Ph.D. Computer Science and Software Engineering Department University of Wisconsin – Platteville 215 Ullrich Hall Platteville, Wisconsin

3 Outline of Presentation 1.Introduction to Ruby 2.Ruby on Rails 3.Model –Viewer – Controller (MVC) and Ruby on Rails 4.Ajax and Ruby on Rails and MCV

4 Ruby on Rails from 40,000 feet Ruby was first released by Yukihiro Matsurnoto in –“I wanted a language more powerful than Perl and more object-oriented than Python.”, Matsurnoto Rails: –Is a framework that allows the rapid development of web applications –Maintains a well-structured code base –Produces a Model-Viewer-Controller (MVC) skeleton for the application –Provides support for asynchronous web updates via AJAX

5 Testimonials Tim O'Reilly, “Ruby on Rails is a breakthrough in lowering the barriers of entry to programming. Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days”. Martin Fowler, “It is impossible not to notice Ruby on Rails. It has had a huge effect both in and outside the Ruby community... Rails has become a standard to which even well established tools are comparing themselves to.”

6 Ruby code examples Ruby Command-line Interpreter (fxri) 001:0> puts "Hello Moon" Hello Moon

7 Heterogeneous Arrays 054:0> # array with 3 elements // a comment 055:0* a = [ 1, “Avogodro", 78.91] => [1, " Avogodro ", 78.91] 056:0> # set first element of a[ ] to 5 057:0* a[ 0 ] = 5 => 5 058:0> # set the second element to :0* a[ 1 ] = 6.02 => :0> a=> [5, 6.02, 78.91]

8 Ruby Count Control Loop 1> 10.downto( 0 ){ 2> |lvc| print lcv, ”__” } 10__9__8__7__6__5__4__3__2__1__0__ downto, as well as upto and others are methods of the Integer Class

9 Ruby Procedures 063:0> # define a procedure called looper 064:0* def looper( count ) 065:1> count.downto( 0 ) { 066:2* |lcv| print lcv, "_" } 067:1> end => nil # execute looper with an argument of 5 069:0* looper( 5 ) 5_4_3_2_1_0_=> 5

10 Characteristics of Ruby Programmers do not need to declare data types. Data types are dynamic Everything is an object Operators (and also array brackets ‘[ ]’) are aliases for object methods Managed memory Has great support for access to OS; CGI; FTP; HTTP; Templates; IP,TCP, UDP Sockets; RegExp; threads/processes; IMAP; POP ; SMTP; Telnet; XML; RUNIT (like JUnit); Win32; databases; and more

11 Introduction to Ruby on Rails Ruby on Rails is an Open Source web application framework –developed by David Hansson in 2004 Follows principle of “Convention Over Configuration” –Rails forces us to follow programming conventions that allow the framework to plug together the pieces automatically.

12 Model-View-Controller (MVC) Rails guides applications into the MVC pattern. MVC Pattern is composed of three components: –Model: maintains the state/data of the system –Controller: the logic center of an application, responsible for: Routing requests from the user to the application Caching to prevent unnecessary queries of the model Session management of application users –Viewer: provides each user with a consistent view of the application based on their state. The goal of MVC is to separate code used for data access from code used for the user interface.

13 MVC Pattern A web browser sends a request to the Controller (1), The Controller interacts with the Model to obtain necessary data (2). The Model queries these data from the database (3) and provides them to the Controller (4), The Controller sends it for rendering to the View (5). The View is then sent to a users browser for viewing (6).

14 MVC and Ruby on Rails Ruby on Rails has a base class for each of the MVC components. –Model inherits from the ActiveRecord class –View inherits from the ActionView class –Controller inherits from the ActionController class

15 The ActiveRecord / Model The ActiveRecord uses Object Relational Mapping (ORM) for storing and retrieving data from a database. –ORM maps DB tables to Ruby Classes –DB rows to Ruby Objects Conventions –If the DB has a table called “products”, then Rails will generate a Class Product in the Model that provides access to the products table. Product.find( ID ) would return a row object from the products DB –DB tables will have plural names, classes will have corresponding singular names.

16 The ActionController Rails provides the three responsibilities of the Controller, Routing, Caching, and Session Management, automatically behind the scenes through the inherited ActionController Class.

17 ActionView The View connects HTML code with the application. “Embedded Ruby” (ERb) supports the implementation of dynamic HTML for web pages in a manner similar to PHP and JSP. Recall the rich support set of Ruby mentioned earlier!

18 Setting Up a MVC App We will need to set up the following: –Database –Controller –View –Model

19 Database setup using SQLit > rails helloworld -d sqlite3 The above rails command will set up three DB environments, one each for : –development –test –production

20 Creating and Provisioning DB Table $ sqlite db/development.sqlite3 sqlite> CREATE TABLE greetings ( "id" INTEGER PRIMARY KEY NOT NULL, "text" VARCHAR(255), "created" DATE ); sqlite> INSERT into greetings values(NULL,"Hello World", " "); sqlite> INSERT into greetings values(NULL,"Hello Bubba", " "); sqlite>select * from greetings;.quit

21 DB Conventions The above example enforces two Rails Conventions –The DB table name is plural “greetings” – this will map to a Ruby Class of “Greeting”. –The primary key to the greeting table is “id”.

22 Setup of Controller > ruby script/generate controller Say The above line creates the shell of a MVC’s Controller called “Say” >class SayController <ApplicationController >end We can define a “hello” method for this class by adding >class SayController <ApplicationController > def hello ># method code goes here. > end

23 Setup of Viewer The generation of the Controller done previously with > ruby script/generate controller Say Created a shell MVC View that we can fill in: 1 2 Hello World 3 4 Hello World 5 6

24 We can now run the app “

25 Setup of Model > ruby script/generate model Greeting Since the DB was generated with the Rails DB generator earlier, the Rails Model generator produces a Controller called “Greeting” that is consistent with the DB. The generator reads the DB schema and generates Class attributes for all of the DB fields and Class methods like: –Greeting.find( ID ) –Greeting.find_all() –...

26 MCV implemented in Ruby on Rails 1.The web browser sends a request that is routed (1a) to a Controller (1b). 2.The Controller executes the requested action (a class method). 3.The Controller has a method, which returns an object of a Model class. 4.The Controller request the data from the Model (2). 5.The Model object queries these data from the database (3) and provides the results to the Controller (4), 6.The Controller sends the results to the View for rendering (5). 7.The View processes the object, generates the output and sends this to the web browser (6).

27 Ajax Asynchronous JavaScript and XML is a key concept in the evolution from the traditional, Web 1.0 to Web 2.0 Web 1.0 generally requires an entire webpage to transmitted and rendered to update content. –All nine components would need to be transmitted and re-rendered if element 9 needed to be changed.

28 Ajax Ajax / Web 2.0 allows web pages to be broken into multiple independent components –When an component needs to be changed, only that component needs to be transmitted and re-rendered. –Thus, the components are asynchronously updated, rather than synchronously updated (like Web 1.0) –Asynchronous updates gives Web Applications the behavior similar to desktop applications and can significantly reduce bandwidth requirements.

29 Ruby on Rails and Ajax Ruby on Rails v1.0 (Dec 2005) allowed single components of Web pages to be updated using Ruby. Ruby on Rails v1.1 (Mar 2006) introduced RJS that generates JavaScript necessary to support Ajax. Ruby on Rails with RJS allows Ajax capabilities without the need to actually write JavaScript.

30 RJS and Rails MVC RJS support Ajax capabilities in the MVC View component.

31 Questions?