Ruby (on Rails) CSE 190M, Spring 2009 Week 3. Web Programming in Ruby Ruby can be used to write dynamic web pages Similar to PHP, chunks of Ruby begins.

Slides:



Advertisements
Similar presentations
Social Web Design 1 Darby Chang Social Web Design.
Advertisements

Molecular Biomedical Informatics Web Programming 1.
WEB PAGES: Create & Maintain Week 12 Creating FORMS.
Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Lecture 11 Server Side Interaction
Modern Web Application Frameworks CSE 591 – Security and Vulnerability Analysis Spring 2015 Adam Doupé Arizona State University
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.
CGI Programming.
1 Chapter 5 – Handling HTML Controls in Web Pages spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
Copyright 2004 Monash University IMS5401 Web-based Systems Development Topic 2: Elements of the Web (g) Interactivity.
28/1/2001 Seminar in Databases in the Internet Environment Introduction to J ava S erver P ages technology by Naomi Chen.
Multiple Tiers in Action
Python and Web Programming
Python Web Applications A KISS Introduction. Web Applications with Python Fetching, parsing, text processing Database client – mySQL, etc., for building.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Web Development Methodologies Yuan Wang(yw2326). Basic Concepts Browser/Server (B/S) Structure Keywords: Browser, Server Examples: Websites Client/Server.
Server Side Scripting Norman White. Where do we do processing? Client side – Javascript (embed code in html) – Java applets (send java program to run.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
PHP: Hypertext Processor Fred Durao
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Advance Database Management Systems Lab no. 5 PHP Web Pages.
PHP MOHAMMED SHURRAB TO MISS/ RASHA ATTALLAH. What is PHP? Stands for "PHP Hypertext Preprocessor" Server-side scripting language HTML-embedded Supports.
1 Chapter 6 – Creating Web Forms and Validating User Input spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
PHP By Jonathan Foss.
CP476 Internet Computing CGI1 CGI is a common way to provide for specific computations on server side, interactions with users, or access to databases.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Introduction to Applets CS 3505 Client Side Scripting with applets.
Java CGI Lecture notes by Theodoros Anagnostopoulos.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
Chapter 6 Server-side Programming: Java Servlets
Introduction to ASP.NET1. 2 Web applications in general Web applications are divided into two parts –The server part –The client part The server part.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
Prof Frankl, Spring 2008CS Polytechnic University 1 Overview of Web database applications with PHP.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
AxKit A member of the Apache XML project Ryan Maslyn Kyle Bechtel.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
 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.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
CSC 2720 Building Web Applications Basic Frameworks for Building Dynamic Web Sites / Web Applications.
Server Side Scripting Perl, Python, Java Servlets  write complete programs in (Perl, Python, Java) to process HTTP requests and generate a complete HTTP.
Basic ActionScript and PHP Cis 126. Getting Started set up a basic folder structure so we can keep our files organized. Mirror this structure on your.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Introduction to CGI PROG. CGI stands for Common Gateway Interface. CGI is a standard programming interface to Web servers that gives us a way to make.
CSE 154 LECTURE 14: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
CSE 154 LECTURE 18: FORMS AND UPLOADING FILES. Exercise: Baby name web service JSON Modify our babynames.php service to produce its output as JSON. For.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP – PHP Hypertext Processor A quick overview. How is PHP used? Embedded with HTML, e.g. Not like CGI: PHP files not an executable Used with servers.
CSE 154 LECTURE 15: EMBEDDED PHP. PHP syntax template HTML content HTML content HTML content... PHP any contents of.
Lesson 11. CGI CGI is the interface between a Web page or browser and a Web server that is running a certain program/script. The CGI (Common Gateway Interface)
PHP / MySQL Introduction
Intro to PHP & Variables
Presentation transcript:

Ruby (on Rails) CSE 190M, Spring 2009 Week 3

Web Programming in Ruby Ruby can be used to write dynamic web pages Similar to PHP, chunks of Ruby begins with " " Ruby code goes between these tags Our web pages will have file extensions of.erb Just like PHP, we cannot view our.erb files from our hard drive; upload it and view it from webster

erb We have been using the Ruby interpreter for our pure Ruby programs For web pages, we need to use a Ruby parser that knows how to deal with embedded Ruby in an HTML file, just like PHP This detail does not really matter… …But for completeness, we are using erb/eruby Thanks to Morgan, this is already setup and configured on webster, so you do not need to worry about it

erb syntax Code Blocks Equivalent to in PHP <% ruby statements %> Printing expression values Equivalent to in PHP

99 Bottles of Beer Write an embedded Ruby file for the 99 Bottles of Beer example from lecture It should generate the HTML for 99 Bottles of Beer

99 Bottles of Beer <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" " CSE 190 M: Embedded Ruby <% num = 99 while num > 0 %> bottles of beer on the wall, bottles of beer. Take one down, pass it around, bottles of beer on the wall. <% num = num - 1 end %>

CGI CGI: Common Gateway Interface "CGI Programming" is a fancy way of saying that we will be writing server side programs that will produce output as a response to a visitors request Ruby has a cgi library to make web programming in Ruby easier

require We want to use functionality from Ruby's cgi library In Java, we would use the keyword "import" import java.io.* To do this in Ruby, we use "require" If we wanted to use the Ruby CGI library: require 'cgi'

Query Parameters To get query parameters, we must create a CGI object Then, we can access the query parameters of a web request through the associative array, with the parameters as the keys Example require 'cgi'# requires the cgi library cgi = CGI.new name = cgi['name']# example.erb?name=Ryan

Query Parameters Accessing the values of parameters returns them as Strings If you want to use them as other values, you need to tell them to behave that way num = cgi['quantity'].to_i You can also check if a parameter is set cgi.has_key?('name')# equivalent to PHP's isset()

99 Bottles of Beer (revisited) CSE 190 M: Embedded PHP <% require 'cgi' cgi = CGI.new if cgi.has_key?('bottles') num = cgi['bottles'].to_i else num = 99 end

99 Bottles of Beer (revisited)(cont.) while num > 0 %> bottles of beer on the wall, bottles of beer. Take one down, pass it around, bottles of beer on the wall. <% num = num - 1 end %>

Query Params and Check Boxes Accessing query parameters like a hash on our CGI object works fine for typical inputs where there is only one value per key But, if we try to get all of the values of a set of checkboxes, only the first value is returned To get all the values, we will use the CGI params() method

Query Params and Check Boxes The CGI params() method returns a hash with the query parameters as the keys of the hash The value of each key is an array of the values of the parameter For parameters with one value, this still returns an array of size one For checkboxes, we are able to get all of the values instead of just the first one

form.html You learn Ruby! You will learn Rails! It is not early in the morning! Homework is optional!

params.erb <% require 'cgi' cgi = CGI.new %> Using the params() method Not using the params() method " %>

Debugging in erb It is not easy… Most errors, especially syntactical errors, result in a "HTTP Error 500: Internal Server Error" It says to Morgan Doocy… but don't, it is just an error in the script Debugging will be easier when we start to use Rails where Rails provides better built-in error handling