Outline. Lecture 18: Ruby on Rails MVC. Introduction to Rails



Similar documents
Ruby on Rails is a web application framework written in Ruby, a dynamically typed programming language The amazing productivity claims of Rails is

Web Development Frameworks

CS169.1x Lecture 5: SaaS Architecture and Introduction to Rails " Fall 2012"

Evaluation. Chapter 1: An Overview Of Ruby Rails. Copy. 6) Static Pages Within a Rails Application

Ruby On Rails. CSCI 5449 Submitted by: Bhaskar Vaish

A Model of the Operation of The Model-View- Controller Pattern in a Rails-Based Web Server

Developing ASP.NET MVC 4 Web Applications MOC 20486

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

Developing ASP.NET MVC 4 Web Applications

The Learn-Verified Full Stack Web Development Program

Dynamic website development using the Grails Platform. Joshua Davis Senior Architect Cognizant Technology Solutions

Modern Web Application Framework Python, SQL Alchemy, Jinja2 & Flask

Standards, Tools and Web 2.0

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led


Pro<DOC/> e-commerce Technology An Introduction

Introduction to Django Web Framework

An Introduction to the Development of Web Applications using Ruby on Rails with Ajax

Agile Web Development with Rails 4

Jaspersoft APIs. Integrating BI with your Applications. Community and Professional Editions

Customer Bank Account Management System Technical Specification Document

Portals and Hosted Files

Design Proposal for a Meta-Data-Driven Content Management System

ActiveVOS Server Architecture. March 2009

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

easyobject modern web applications made easy Project presentation

Ruby on Rails. a high-productivity web application framework. blog.curthibbs.us/ Curt Hibbs <curt@hibbs.com>

Drupal CMS for marketing sites

1. Was ist das? II. Wie funktioniert das? III. Wo funktioniert das nicht?

A Tour of Ruby on Rails

Enterprise Application Development In Java with AJAX and ORM

Web Application Development and Frameworks

Web Development with Flask and the Raspberry Pi Leading by Example CUAUHTEMOC CARBAJAL ITESM CEM 22/04/2014

NoSQL web apps. w/ MongoDB, Node.js, AngularJS. Dr. Gerd Jungbluth, NoSQL UG Cologne,

Acquia Introduction December 9th, 2009

What s really under the hood? How I learned to stop worrying and love Magento

Brakeman and Jenkins: The Duo Detects Defects in Ruby on Rails Code

ASP.NET Using C# (VS2012)

Server-side OSGi with Apache Sling. Felix Meschberger Day Management AG 124

Ruby on Rails is a Web application framework for Ruby. It was first released to the public in July2004.

Introduction to Ruby on Rails

Web Development Frameworks. Matthias Korn

Getting Started with Web Applications

WIRIS quizzes web services Getting started with PHP and Java

A Comparison of Open Source Application Development Frameworks for the Enterprise

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

T320 E-business technologies: foundations and practice

White Paper On. Single Page Application. Presented by: Yatin Patel

Java EE 7: Back-End Server Application Development

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Ruby on Rails in GlassFish Sun Microsystems

VOIP and Ruby. The Convergence of Web and Voice Applications using Open Source Software. Justin Grammens Localtone Interactive

WebSphere Portal Server and Web Services Whitepaper

Copyright 2013 X.commerce, Inc. All rights reserved

Getting Started with Telerik Data Access. Contents

Rails Cookbook. Rob Orsini. O'REILLY 8 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo

JAVA/J2EE DEVELOPER RESUME

Performance Comparison of Persistence Frameworks

Oracle Application Development Framework Overview

How To Build A Web App

Progressive Enhancement With GQuery and GWT. Ray Cromwell

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

Java in Web 2.0. Alexis Roos Principal Field Technologist, CTO Office OEM SW Sales Sun Microsystems, Inc.

Designing and Developing Web Applications by using the Microsoft.NET Framework

ASP.NET MVC. in Action JEFFREY PALERMO JIMMY BOGARD BEN SCHEIRMAN MANNING. (74 w. long.) WITH MVCCONTRIB, N HIBERNATE, AND MORE.

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

MVC pattern in java web programming

Architecture Guide Jahia EE v6.1

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

Getting Started Developing JavaScript Web Apps. this = that. VT Geospatial Forum 2015

Symfony2 and Drupal. Why to talk about Symfony2 framework?

TIBCO ActiveMatrix Service Bus Getting Started. Software Release 2.3 February 2010

Inside the Digital Commerce Engine. The architecture and deployment of the Elastic Path Digital Commerce Engine

SAP Web Application Server 6.30: Learning Map for Development Consultants

AGILE PROGRAMMING AND DESIGN PATTERNS IN WEB DEVELOPMENT -A CASE STUDY

1 What Are Web Services?

In this chapter, we lay the foundation for all our further discussions. We start

Crystal Reports for Borland JBuilder

Slides from INF3331 lectures - web programming in Python

Web Applications: Overview and Architecture

Rhomobile cross-platfrom

Ruby on Rails. Object Oriented Analysis & Design CSCI-5448 University of Colorado, Boulder. -Dheeraj Potlapally

Cache Configuration Reference

CIS 192: Lecture 10 Web Development with Flask

SwiftScale: Technical Approach Document

Building Dynamic Web 2.0 Websites with Ruby on Rails

Table of Contents. Magento Certified Developer Exam Study Guide

Chapter 22: Integrating Flex applications with portal servers

Building Web Applications, Servlets, JSP and JDBC

Catalog Web service and catalog commerce management center customization

Enterprise Service Bus

Ruby on Rails. Mitchell Craig; Tam Nguyen; Becker Luu; Eliezer Mar Manarang; and Colin Williams University of Calgary SENG 403 Dr.

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

General principles and architecture of Adlib and Adlib API. Petra Otten Manager Customer Support

MS-55052: SharePoint 2013 End User Level II

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

PROGRESS Portal Access Whitepaper

Pete Helgren Ruby On Rails on i

Beginning POJOs. From Novice to Professional. Brian Sam-Bodden

Rapid Application Development. and Application Generation Tools. Walter Knesel

Transcription:

Outline Lecture 18: Ruby on Rails Wendy Liu CSC309F Fall 2007 Introduction to Rails Rails Principles Inside Rails Hello World Rails with Ajax Other Framework 1 2 MVC Introduction to Rails Agile Web Development with Rails 2 nd Ed, D. Thomas et al. 3 4 1

Rails Rails enforces a structure for the application MVC architecture Models, views, and controllers are developed as separate chunks of functionality and knitted together by Rails Little external configuration metadata is needed Convention over configuration philosophy A Typical Rails Application Incoming requests are first sent to a router, which determines where to send and how to parse the request A particular method, or action, is called in some controller The action might look at data in the request, interact with the model, or cause other actions to be invoked The action prepares information for the view, which renders the output to the user 5 6 Rails and MVC Why Rails MVC seems to do the trick, why do we need Rails? Rails handles all of the low-level housekeeping for you all those messy details that take so long to handle by yourself and lets you concentrate on your application s core functionality Controller: store Action: add_to_cart Model: (shopping cart) params[:id] 123 7 8 2

Rails Principles Painstaking Mappings Mappings we have seen and used Deployment descriptors Servlet mappings (URL to Servlet class) Persistence data binding JDBC data mappings (Class to table) Transport data binding WSDL and JAX-B data binding (Class/Field to XML element/attribute) MVC mapping Model to View to Controller (usually hard coded) All stored and performed differently Learning curve, maintenance cost 9 10 Top Two Principles Convention over configuration No explicit mapping needed Such as deployment descriptors Use naming conventions to automatically perform the mapping E.g. Store controller vs. store view To fight back the proliferation of configurations seen in J2EE DRY (Don t Repeat Yourself) Information is located in a single, unambiguous place 11 Inside Rails 12 3

Components of Rails Active Record Model Action Pack View and Controller OO vs RDB Applications are often Object Oriented, they also keep information in a relational database Relational databases are designed around mathematical set theory All about sets of values Objects are all about data and operations Operations that are easy to express in relational terms are sometimes difficult to code in an OO system, and vice versa 13 14 Object-Relational Mapping (ORM) ORM libraries map database tables to classes If a database has a table called orders, we will have a corresponding class named Order Rows in this table correspond to objects (instances) of the class A particular order is represented as an object of class Order Within that object, attributes are used to get and set the individual columns Our Order object has methods to get and set the amount, the sales tax, and so on ORM (cont d) Rails (model) classes provide a set of classlevel methods that perform table-level operations For example, we might need to find the order with a particular id This is implemented as a class method that returns the corresponding Order object 15 16 4

Active Record Model support in Rails The ORM layer supplied with Rails tables map to classes, rows to objects, and columns to object attributes Example: Active Record SQL CREATE TABLE people ( id INT(11) NOT NULL auto_increment, name VARCHAR(100), PRIMARY KEY (id) ) Active Record class Person < ActiveRecord::Base; end Person.create(:name => "Lucas Carlson") lucas = Person.find_by_name("Lucas Carlson") lucas.name = "John Doe" lucas.save 17 18 Action Pack Bundles both views and controllers The view and controller parts of MVC are pretty intimate The controller supplies data to the view The controller receives events from the pages generated by the views Rails provides a clear separation for control and presentation logic Action Pack: View Support Creating either all or part of a page to be displayed in a browser Dynamic content is generated by templates rhtml Embeds snippets of Ruby code within the view s HTML rxml Lets you construct XML documents using Ruby code The structure of the generated XML will automatically follow that of the code rjs Allows you to create JavaScript fragments on the server which are to be executed on the browser Great for creating dynamic Ajax interfaces 19 20 5

Example: Rails View <h1>hello world!</h1> <p>the count is <%= @some_number %></p> <ul> <% for i in 0..@some_number do %> <li><%= i %></li> <% end %> </ul> 21 Action Pack: Controller Coordinates the interaction between the user, the views, and the model Rails handles most of this interaction behind the scenes You only need to add the application-level functionality Other responsibilities Routing external requests to internal actions Managing caching Give applications orders-of-magnitude performance boosts Managing helper modules Extend the capabilities of the view templates without bulking up their code Managing sessions Giving users the impression of ongoing interaction with the applications 22 Example: Rails Controller class PersonController < ApplicationController def index # local to the method ONLY some_number = 5 end def count # local to the method AND the view @some_number = 5 end end How to Interpret URLs in Rails Example: http://localhost:3000/person/count/123 person translates to the PersonController class count translates to the count method 123 translates to the value of params[:id] 23 24 6

ActionWebServices That's Not All Create SOAP and XML-RPC web services in minutes XML views Create RSS in seconds Easy, well integrated unit testing Automated documentation generation Automated benchmarking and integrated logging Interactive debugger Easy custom routes Plug-ins 25 26 Create Application: demo Hello World Build a Rails App: Illustrating Convention over Configuration 27 28 7

Directory Listing: demo Starts Web Server Starts a stand-alone web server that can run our newly created Rails application under WEBrick (default) 29 30 Newly Created Rails Application Create New Controller: Say 31 32 8

Inside Say Controller Add Method to Say Controller 33 34 URLs: Mapped to Controllers and Actions Rails Routes to Controllers and Actions 35 36 9

Go to the Link http://localhost:3000/say/hello Create a Template (View) By default, Rails looks for templates in a file with the same name as the action it s handling We need to create a file called hello.rhtml in the directory app/views/say/ 37 38 Hello! Standard Locations for Controllers and Views 39 40 10

Adding Dynamic Content Hello and Goodbye! 41 42 Story So Far 1. The user navigates to our application In our case, we do that using a local URL such as http://localhost:3000/say/hello 2. Rails analyzes the URL The say part is taken to be the name of a controller, so Rails creates a new instance of the Ruby class SayController (which it finds in app/controllers/say_controller.rb) 3. The next part of the URL path, hello, identifies an action Rails invokes a method of that name in the controller This action method creates a new Time object holding the current time and tucks it away in the @time instance variable 43 Story So Far (cont d) 3. Rails looks for a template to display the result It searches the directory app/views for a subdirectory with the same name as the controller (say) and in that subdirectory for a file named after the action (hello.rhtml) 4. Rails processes this template through ERb (Embedded Ruby), executing any embedded Ruby and substituting in values set up by the controller 5. The result is returned to the browser, and Rails finishes processing this request 44 11

RJS Template Rails with Ajax Idea: Your XHR calls can return JavaScript to execute in the browser Solving problems that otherwise require a great deal of complex JavaScript on the client A RJS template is a file in app/views/ with an.rjs extension When a request comes in from XHR, the dispatcher will preferentially look for an.rjs template The template is parsed, JavaScript is generated and returned to the browser, where it is finally executed 45 46 Related Framework Other Framework Django for Python Features: MVC-based Object-relational mapping DRY (Don t Repeat Yourself) Principle Ease the creation of complex, DB-driven web development Emphasize reusability and pluggability Automate as much as possible Support for rapid development http://www.djangoproject.com/ 47 48 12