CMPE/SE 131 Software Engineering September 6 Class Meeting Department of Computer Engineering San José State University Fall 2016 Instructor: Ron Mak

Slides:



Advertisements
Similar presentations
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Advertisements

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.
Objective Understand web-based digital media production methods, software, and hardware. Course Weight : 10%
Web Page Behavior IS 373—Web Standards Todd Will.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
UNIT-V The MVC architecture and Struts Framework.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
AJAX Chat Analysis and Design Rui Zhao CS SPG UCCS.
Server-side Scripting Powering the webs favourite services.
Web application architecture
Web Application Programming Carol Wolf Computer Science.
MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Chapter 8 Cookies And Security JavaScript, Third Edition.
10/13/2015 ©2006 Scott Miller, University of Victoria 1 Content Serving Static vs. Dynamic Content Web Servers Server Flow Control Rev. 2.0.
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
CS 174: Web Programming October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
Lecture 13b Rails – Controllers and Views Topics SaaSSaaS Readings: SaaS book Ch March 3, 2014 CSCE 740 Software Engineering.
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
RESTful Web Services What is RESTful?
Ruby on Rails Controller of MVC. Routes How we map URIs like /tweets/1 to calling the show method of the Controller.
Rails and routing INFO 2310: Topics in Web Design and Programming.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
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.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
Understanding Web-Based Digital Media Production Methods, Software, and Hardware Objective
Leveraging Web Content Management in SharePoint 2013 Christina Wheeler.
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.
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
National College of Science & Information Technology.
CMPE/SE 131 Software Engineering September 1 Class Meeting Department of Computer Engineering San José State University Fall 2016 Instructor: Ron Mak
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
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.
Pre-Production Meet with the client to create a project plan:
Introduction to Dynamic Web Programming
Section 6.3 Server-side Scripting
WWW and HTTP King Fahd University of Petroleum & Minerals
Tutorial 10 Programming with JavaScript
1993 version of Mosaic browser.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Data Virtualization Tutorial… CORS and CIS
CMPE 280 Web UI Design and Development October 26 Class Meeting
Introduction Web Environments
CMPE 280 Web UI Design and Development October 24 Class Meeting
PHP / MySQL Introduction
Intro to PHP & Variables
CMPE 280 Web UI Design and Development January 30 Class Meeting
Testing REST IPA using POSTMAN
Ruby on Rails by Manik Juneja
CISC103 Web Development Basics: Web site:
(Includes setup) FAQ ON DOCUMENTS (Includes setup)
CS 174: Server-Side Web Programming January 29 Class Meeting
Ruby on Rails by Manik Juneja
Controllers.
CMPE 280 Web UI Design and Development January 30 Class Meeting
Objective Understand web-based digital media production methods, software, and hardware. Course Weight : 10%
Chapter 15 Introduction to Rails.
CMPE 280 Web UI Design and Development January 29 Class Meeting
J2EE Lecture 1:Servlet and JSP
An Introduction to JavaScript
CMPE/SE 131 Software Engineering February 7 Class Meeting
CMPE/SE 131 Software Engineering February 9 Class Meeting
Client-Server Model: Requesting a Web Page
(Includes setup) FAQ ON DOCUMENTS (Includes setup)
Presentation transcript:

CMPE/SE 131 Software Engineering September 6 Class Meeting Department of Computer Engineering San José State University Fall 2016 Instructor: Ron Mak

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Eclipse Ruby Plugin  Ruby DLTK Dynamic Languages Toolkit  See 2

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak More on Routing  Several tutorials on the web about Rails routing. Google “rails routing tutorial” 3

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Database Actions and HTTP Verbs  Mapping between database CRUD actions and HTTP verbs:  A web browser is only able to issue GET and POST requests.  Therefore, Rails fakes the PATCH and DELETE requests. 4 Database actionHTTP verb createPOST readGET updatePATCH deleteDELETE

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Default RESTful Actions  Rails uses REST, which expands the read database action into four RESTful actions: 5 RESTful actionHTTP verbDescription indexGETList all records. showGETShow one record. newGETShow a form to create a new record. editGETShow a form to edit an existing record. createPOSTCreate a new record. updatePATCHUpdate an existing record. destroyDELETEDelete a record.

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Display the Application’s Routes  The combination of the HTTP verb and the URL pattern determines the controller action. 6 ~/ruby/code/blog: bin/rake routes Running via Spring preloader in process 1581 Prefix Verb URI Pattern Controller#Action post_comments POST /posts/:post_id/comments(.:format) comments#create posts GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post GET /posts/new(.:format) posts#new edit_post GET /posts/:id/edit(.:format) posts#edit post GET /posts/:id(.:format) posts#show PATCH /posts/:id(.:format) posts#update PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy login GET /login(.:format) user_session#new POST /login(.:format) user_session#create logout DELETE /logout(.:format) user_sessions#destroy root GET / posts#index

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak The Route Prefix  The route prefix determines which Rails path and URL helper function to use.  A URL helper generates a URL that includes the protocol, server, port, and path.  A path helper only generates the path.  Use the helpers in your controller and view code instead of hardcoding paths and URLs. 7 ~/ruby/code/blog: bin/rake routes Running via Spring preloader in process 1581 Prefix Verb URI Pattern Controller#Action post_comments POST /posts/:post_id/comments(.:format) comments#create posts GET /posts(.:format) posts#index POST /posts(.:format) posts#create

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Path and URL Helper Functions  Use the helpers in your controller and view code instead of hardcoding paths and URLs. 8 Path helpersURL helpers post_pathpost_url post_path(id)post_url(id) new_post_pathnew_post_url edit_post_path(id)edit_post_url(id) post_comments_path(id)post_comments_url(id) login_pathlogin_url logout_pathlogout_url root_pathroot_url

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Path and URL Helper Functions, cont’d  Test the helper functions: 9 irb(main):023:0> app.posts_path => "/posts" irb(main):024:0> app.posts_url => " irb(main):025:0> app.post_path(3) => "/posts/3" irb(main):026:0> app.new_post_url => " irb(main):027:0> app.post_comments_path(4) => "/posts/4/comments" irb(main):028:0> app.login_path => "/login" irb(main):029:0> app.root_url => "

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Views  The view is your application’s user interface.  Presents a user-friendly visual rendition of the application’s model. 10

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Embedded Ruby  An embedded Ruby.erb file is a template from which Rails generates an HTML page.  The HTML page contains embedded Ruby code that executes before the page is sent to the client.  The embedded Ruby code dynamically creates content which replaces the embedded code within the HTML page. 11

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Output Tags  Output tags. Example: app/views/post/show.html.erb 12 Title: Body: | Path helpers

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Control Flow Tags  Tags enclose Ruby code that executes to do control flow. Example: app/views/post/index.html.erb 13 <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Helpers  Ruby methods that simplify your view code. create links format numbers other common tasks  Avoid having too much embedded code.  Write your own helpers. 14

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Helpers, cont’d  URL helpers Example: generates  Number helpers number conversion number formatting 15 link_to 'Show', post Show

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Write Your Own Helpers  Put in app/helpers Example: app/helpers/post_helper.rb for post views. 16 module ApplicationHelper def friendly_date(d) d.strftime("%B %e, %Y") end friendly_date Time.new(2016, 9, 8)

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Index Page Generation Example  The index page is dynamically generated. 17

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Index Page Generation Example, cont’d 18 Listing Posts Title Body... app/views/posts/index.html.erb

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Index Page Generation Example, cont’d <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %> Instance was initialized by the Post controller’s index action. def = Post.all end Fake the DELETE request. app/views/posts/index.html.erb

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Layouts  Good UI design includes having a consistent layout for your application’s web pages. common headers, footers. common page structure etc.  A Rails layout is a file containing the common HTML code for every application page. 20

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Layouts, cont’d 21 Blog <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> Change to default for Windows. Assets such as JavaScript and CSS files are kept in app/assets. Security helper to protect against cross-site request forgery (CSRF). app/views/layouts/application.html.erb

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Partials  A partial is a snippet of view code that is “included” by other view code.  This allows the same display elements to be repeated on different pages. By convention, names of partial start with _ Example: 22 said: app/views/comments/_comments.html.erb

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Displaying Comments 23 | Comments  Display the comments for a post at the bottom of the page that shows that post. app/views/posts/show.html.erb

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Forms  HTML forms enable users to submit data to the application code running on the web server. Create the form with a partial so it can be reused. 24

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Post Form 25 prohibited this post from being saved:... Check for and handle form errors. Bind a form to a model. app/views/posts/_form.html.erb

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Post Form, cont’d app/views/posts/_form.html.erb

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Form Errors  Try to create a post with an empty title. 27

Computer Engineering Dept. Fall 2016: September 6 CMPE/SE 131: Software Engineering © R. Mak Comment Form  Add the form to create comments for a post at the bottom of the page that shows that post. 28 app/views/posts/show.html.erb