Ajax and Ruby on Rails Session 9 INFM 603.

Slides:



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

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 16 Introduction to Ajax.
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.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
Chapter 15 © 2010 by Addison Wesley Longman, Inc Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in Use spread rapidly.
PHP (2) – Functions, Arrays, Databases, and sessions.
Debugging and Ajax Session 7 INFM 718N Web-Enabled Databases.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
INTRODUCTION The Group WEB BROWSER FOR RELATION Goals.
Week 1 INFM 718N Web-Enabled Databases The Big Picture.
XML + Ajax Week 13 INFM 603.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
E-Commerce The technical side. LAMP Linux Linux Apache Apache MySQL MySQL PHP PHP All Open Source and free packages. Can be installed and run on most.
INTRO TO MAKING A WEBSITE Mark Zhang.  HTML  CSS  Javascript  PHP  MySQL  …That’s a lot of stuff!
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
UNIT-V The MVC architecture and Struts Framework.
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
Intro to Web Programming using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
AJAX Chat Analysis and Design Rui Zhao CS SPG UCCS.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Databases and the Internet. Lecture Objectives Databases and the Internet Characteristics and Benefits of Internet Server-Side vs. Client-Side Special.
PHP. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for.
Lecture 7 Interaction. Topics Implementing data flows An internet solution Transactions in MySQL 4-tier systems – business rule/presentation separation.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Content Management Systems Week 14 LBSC 671 Creating Information Infrastructures.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
JavaScript – Quiz #9 Lecture Code:
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
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.
Web Design: Basic to Advanced Techniques Fall 2010 Mondays 7-9pm 200 Sutardja-Dai Hall Introduction to PHP.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Creating Databases for Web applications Server side vs client side PHP basics Homework: Get your own versions of sending working: both html and Flash!
 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.
Weekend MS CS Program Internet and Web Technologies COT 5930 Web Project Development - Ajax Dr. Roy Levow, Associate Chair & Professor
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
ICM – API Server & Forms Gary Ratcliffe.
Introduction to Ruby&Rails Yuri Veremeyenko Monica Verma.
The basics of knowing the difference CLIENT VS. SERVER.
AJAX. Overview of Ajax Ajax is not an API or a programming language Ajax aims to provide more responsive web applications In normal request/response HTTP.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
AJAX in Ruby-on-Rails. Ruby on Rails and AJAX AJAX can be done with just Javascript Easier if you use libraries –Prototype –SAJAX –jQuery Libraries only.
PHP Form Processing * referenced from
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
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.
Web Services Essentials. What is a web service? web service: software functionality that can be invoked through the internet using common protocols like.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
START Application Spencer Johnson Jonathan Barella Cohner Marker.
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
National College of Science & Information Technology.
Introduction to Dynamic Web Programming
Content Management Systems
PHP / MySQL Introduction
Chapter 15 Introduction to Rails.
Presentation transcript:

Ajax and Ruby on Rails Session 9 INFM 603

Agenda Ajax Ruby Rails (Model-View-Controller)

Server-side Programming Interchange Language Client-side Programming Relational normalization Structured programming Software patterns Object-oriented design Functional decomposition Client Hardware (PC, Unix) (MySQL) (PHP) (HTML, XML) (JavaScript) (IE, Firefox) (PC) Business rules Interaction Design Interface Web Browser Server-side Programming Interchange Language Client-side Programming Database Server Hardware

Sajax: Simple Ajax for PHP http://www.modernmethod.com/sajax/ <? require("Sajax.php"); function multiply($x, $y) { return $x * $y; } sajax_init(); // $sajax_debug_mode = 1; sajax_export("multiply"); sajax_handle_client_request(); ?>

<html><head> <title>Multiplier</title> <script> <? sajax_show_javascript(); ?> function do_multiply_cb(z) { document.getElementById("z").value = z; } function do_multiply() { // get the folder name var x, y; x = document.getElementById("x").value; y = document.getElementById("y").value; x_multiply(x, y, do_multiply_cb); </script> </head> <body> <input type="text" name="x" id="x" value="2" size="3"> * <input type="text" name="y" id="y" value="3" size="3"> = <input type="text" name="z" id="z" value="" size="3"> <input type="button" name="check" value="Calculate" onclick="do_multiply(); return false;"> </body></html>

Communication methods GET/POST (client to server) – simple data XML (the “X” in AJAX) Structured data between client and server. Client responsible for updating page JSON – a light-weight alternative to XML HTML (server to client) – server sends rendered result Widget – GUI library hiding (some) AJAX details (e.g. DoJo)

Ruby http://tryruby.org 2+2 puts “Hello world!” backward = “Hello world”.reverse backward.capitalize numbers = [12, 3, 10] numbers.sort! numbers

Variables and Operators Ruby variables are not specially marked size = 12 Variables can hold any value type Similar operators to PHP, Javascript + / == &&

String handling String concatenation is “+” (like Javascript, unlike PHP!): puts “My name is “ + name Strings can also be interpolated: puts “My name is #{ name }” puts “Two plus two is #{ 2 + 2 }” Single quoting turns off interpolation

Objects Ruby has objects Object method reference is using “.” user = User.new(“John”, “Doe”) Object method reference is using “.” user.set_given_name(“Jane”) No-argument methods don’t need () user.get_given_name

Arrays and Hashes Ruby has numerically-indexed arrays fruits = [“mango”, “orange”, “apple” ] fruits[1] # mango Ruby also has string-indexed hashes food = {“mango” => “fruit”, “pear” => “fruit”, “onion” => “vegie”} food[“onion”] # “vegie” The “=>” operator links keys with values (also used outside of hashes)

Symbols Ruby has a special type called symbols :author => “Jane” A symbols means … itself! Think of them as a kind of keyword create_table :users do |t| t.column :name, :string,:limit=>11 t.column :password, :string end

Model-View-Controller

Simple MVC in WebApps Model: database and code to handle basic CRUD (Create, Read, Update, Delete) functions View: dynamic web interface, populated with server-side variables Controller: code in between: extracts information for views, executes updates from user

Without MVC separation $result = mysql_query(“SELECT given, family FROM User WHERE login=‘” . mysql_real_escape_string(S_GET[“uid”]) . “’”); # NOTE: no error handling! $fields = mysql_fetch_assoc($result); $given = $fields[“given”]; # Populate other information ... <form method=“post”> Given name: <input name=“given” value=“<?php print $given ?>”> <!-- what about unclean characters? --> <input type=“submit” name=“Update” value=“update”> </form>

Without MVC separation (cont.) # This code would actually go at the _start_ of the # php code file if (isset($_POST[“Update”])) { # Error checking and handling mysql_query(“UPDATE User SET given = ‘” . mysql_real_escape_string($_POST[“given”]) . “’”); # More error checking # Possible redirect? }

MVC separation in Rails app views users forums models controllers

Wrapper, scaffold, generation MVC discipline allows: Wrapper code: re-usable code for performing common tasks Scaffold code: basic implementations (e.g. of editing a user) that can be replaced when ready Generation: auto-generation of template code to be extended

Generating Templates ruby script/generate model employee self.up method creates a database table sele.down method drops that table ruby script/generate controller employees Creates generic methods new, index, show, edit Creates matching views

Object-relational model (ORM) In naïve webapp, data has three lives: Row in database Variable in program (field of object) Parameter in request (HTTP POST) ORM wraps database in object-oriented code (table rows look like objects) MVC allows near-transparent extension to Web forms, parameters.

Rails and AJAX MVC AJAX: a view within a view Request minimally rewritten link_to becomes link_to_remote identify target for result Response sends HTML code for updated division within full HTML page