Chapter 15 Introduction to Rails.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
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.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Chapter 15 © 2010 by Addison Wesley Longman, Inc Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in Use spread rapidly.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 Chapter 12 Working With Access 2000 on the Internet.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 24 – Web Servers (PWS, IIS, Apache, Jigsaw) Outline 24.1Introduction 24.2Microsoft Personal.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Server-side Scripting Powering the webs favourite services.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
1 An Introduction to the Development of Web Applications using Ruby on Rails with Ajax Ansgar Berhorn, B.Sc. and Mike Rowe, Ph.D.
Elements of ASP Documents Adapted from MCDN Web Workshop ( and Webmonkey’s Introduction to Active.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Chapter 15 © 2009 by Addison Wesley Longman, Inc Overview of Rails - Rails is a development framework for Web-based applications - Rails is written.
4 Chapter Four Introduction to HTML. 4 Chapter Objectives Learn basic HTML commands Discover how to display graphic image objects in Web pages Create.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Windows 7 WampServer 2.1 MySQL PHP 5.3 Script Apache Server User Record or Select Media Upload to Internet Return URL Forward URL Create.
CP476 Internet Computing Perl CGI and MySql 1 Relational Databases –A database is a collection of data organized to allow relatively easy access for retrievals,
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
NMD202 Web Scripting Week2. Web site
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
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.
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
Web Database Programming Using PHP
Managing, Storing, and Executing DTS Packages
Databases.
Project 1 Introduction to HTML.
Introduction to Dynamic Web Programming
Working in the Forms Developer Environment
Creating a Basic Form Module
Chapter 6 - Database Implementation and Use
Chapter 1 Introduction to HTML.
Introduction and Principles
Web Database Programming Using PHP
Play Framework: Introduction
Database application MySQL Database and PhpMyAdmin
Introduction to Web programming
PHP Training at GoLogica in Bangalore
PHP / MySQL Introduction
Intro to PHP & Variables
Department of Computer Science, Florida State University
MVC Framework, in general.
ISC440: Web Programming 2 Server-side Scripting PHP 3
MSIS 655 Advanced Business Applications Programming
Web Development Using ASP .NET
Chapter 27 WWW and HTTP.
Web Systems Development (CSC-215)
PHP.
Web DB Programming: PHP
Server-Side Processing II
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Spreadsheets, Modelling & Databases
PHP an introduction.
Web Application Development Using PHP
Presentation transcript:

Chapter 15 Introduction to Rails

15.1 Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the Model-View-Controller architecture Model classes are the data classes, including constraint enforcement View classes present the data to the user Controller classes perform computations and deal with user interaction Rails uses an Object-Relational Mapping approach to working with databases A cars table corresponds to a car class The rows of the table correspond to instances of the class The correspondence is built automatically by the Rails framework Rails uses a combination of Ruby code and template files to create responses

15.1 Developer Tasks Design and build the model, including a database for storing model data Design and implement actions Design and implement the views

15.2 Document requests The Rails framework provides much of the superstructure necessary for a web application Scripts with the Rails framework set up the basic structure The first Rails example serves a single static document

15.3 Project Setup The InstantRails package provides all the components needed to develop and test Rails projects on a Microsoft Windows platform Start the InstantRails console InstantRails Set up a rails application rails rails1 Generate a controller ruby script/generate controller say Run the default server ruby script/server The server runs for a particular application

15.3 Project Directory Structure

15.2 Project Components A controller class, SayController, in the controllers directory The controller class has method named hello An html template file (static for this example) named hello.rhtml in directory views\say The Rails framework associates these components by the name ‘say’

15.2 Request Processing

15.2 Dynamic Documents The next example displays the greeting but also displays the current time Uses Time.now from the Ruby library <% … %> embeds Ruby code in template files <%= … %> causes the value of the executed code to be inserted in place Instance variables of the controller class can be accessed in the template file

15.3 Processing Forms The popcorn example is used to illustrate accessing information from forms

15.3 Setting Up the Applications A controller home is created An empty action method the_form is created A static template file the_form.rhtml is created to display the initial data entry form The action on the form is simply “result” which links to an action method named result in the same controller class

15.3 The Controller and the View Action method result in the controller class Get form data Compute results Object params holds the form data in a hash-like object Can be indexed by symbols or by strings using widget names params[:phone] gets the phone number params[:unpop].to_i gets the unpopped amount as an integer The sprintf method can be used to format data Used with format specification %5.2d to format floating numbers with exactly two decimal places

15.4 Rails Applications with Databases This example uses the Corvettes database The user specifies model year limits and body styles The response is a list of matching cars

15.4 Building the Database A database is created with four tables using MySQL commands A script file is used to make the typing easier Tables are named with plural names because of Rails names corresponding classes with the singular Model classes are created ruby script/generate model corvette Directives in the model files specify the table relations has_many belongs_to

15.4 Building the Application A table object gives access to the data in the table Method count gives the number of rows Method find is used to search Method find One parameter is a primary key search. The matching row is returned Parameter :all requires a second parameter giving the value of the :conditions symbol, a test condition. All matching rows are returned Parameter :first requires a second parameter giving the value of the :conditions symbol, a test condition. The first matching row is returned Method find_by_sql takes an SQL SELECT command The action methods query the database and put results into instance variables The matching template displays the results

15.5 Layouts A layout template provides a standard template for other templates Put in the layouts directory Put a layout command in the ApplicationController class The layout template can provide header and styling directions while other templates provide content The @content_for_layout variable in the layout template provides the content from the other template