CS 142 Lecture Notes: Rails Controllers and Views

Slides:



Advertisements
Similar presentations
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 1 Simple Rails Template
Advertisements

CS 142 Lecture Notes: HTMLSlide 1 Introduction This article is a review of the book Dietary Preferences of Penguins, by Alice Jones and Bill Smith. Jones.
XHTML II DIGITAL MEDIA: COMMUNICATION AND DESIGN F2007.
CS 142 Lecture Notes: HTMLSlide 1 Introduction There are several good reasons for taking CS142: Web Applications: ● You will learn a variety of interesting.
F DIGITAL MEDIA: COMMUNICATION AND DESIGN INTRODUCTION TO XML AND XHTML.
XHTML and Forms Review – Page 1CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Review XHTML and Forms.
Using Html Basics, Text and Links. Objectives  Develop a web page using HTML codes according to specifications and verify that it works prior to submitting.
Chapter 15 © 2009 by Addison Wesley Longman, Inc Overview of Rails - Rails is a development framework for Web-based applications - Rails is written.
XHTML1-1 Extensible HyperText Markup Language (XHTML) Part 2 Xingquan (Hill) Zhu
Images and Tables ables.asp.
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
CIS 375—Web App Dev II JavaScript I. 2 Introduction to DTD JavaScript is a scripting language developed by ________. A scripting language is a lightweight.
The Controller Carol Wolf Computer Science. Rails generate commands  Using the generate command, you can create a number of useful objects.  Rails:
CIS 228 The Internet 9/20/11 XHTML 1.0. “Quirks” Mode Today, all browsers support standards Compliant pages are displayed similarly There are multiple.
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.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
School of Business Administration HTML, Expression Web, WinSCP, &
What is XHTML? XHTML stands for Extensible Hypertext Markup Language
CSE 102 Introduction to Web Design and Programming
CSE 102 Introduction to Web Design and Programming
RDF and RDB 2 D2RQ.
CSE 102 Introduction to Web Design and Programming
CIS 228 The Internet 9/20/11 XHTML 1.0.
JavaScript: Control Structures I
CSE 102 Introduction to Web Design and Programming
CSE 102 Introduction to Web Design and Programming
Advanced Web Development IT225
Introduction to PHP FdSc Module 109 Server side scripting and
RDF and RDB 2 D2RQ.
W3C Web standards and Recommendations
Chapter 44 JavaServer Face
XHTML Basics.
What is XHTML?.
Web Development & Design Foundations with HTML5 8th Edition
Using the Internet to publish data and applications
HTML Layout and Sub Meun
XHTML 1 by Carsomyr.
CSE 102 Introduction to Web Design and Programming
XHTML Basics.
XHTML
XHTML Basics.
HTML A brief introduction HTML.
JavaScript: Arrays.
Chapter 8 - JavaScript: Control Structures I
Chapter 9 - JavaScript: Control Structures II
Introduction There are several good reasons for taking CS142: Web Applications: You will learn a variety of interesting concepts. It may inspire you to.
JavaScript: Functions
JavaScript: How To? B. Ramamurthy.
CS 142 Lecture Notes: Rails Controllers and Views
Instructor: Charles Moen
Your Page and Review Objectives
CS 142 Lecture Notes: Cookies
Note that iframes are available in HTML5.
Chapter 15 Introduction to Rails.
XHTML Basics.
CSCI 2910 Client/Server-Side Programming
RDF and RDB 2 D2RQ.
Chapter 7 - JavaScript: Introduction to Scripting
Creating a Basic Web Page
XHTML Basics.
XHTML 7-May-19.
XHTML Basics.
XHTML Validation.
XHTML 29-May-19.
محمد احمدی نیا XHTML محمد احمدی نیا
Chapter 8 - JavaScript: Control Structures I
Web Design & Development
Your Page and Review.
Creating Web Documents
Presentation transcript:

CS 142 Lecture Notes: Rails Controllers and Views Simple Rails Template <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Hello, User</title> </head> <body> <p> This page was fetched at <%= Time.now() %> </p> </body> </html> CS 142 Lecture Notes: Rails Controllers and Views

Control Structures in Templates ?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Rails Parameters</title> </head> <body> <p> The <code>params</code> hash contains the following values: </p> <% params.each do |key, value| %> <p><%= key %>: <%= value %></p> <% end %> </body> </html> CS 142 Lecture Notes: Rails Controllers and Views

Control Structures, cont’d Template: ... <% params.each do |key, value| %> <p><%= key %>: <%= value %></p> <% end %> HTML: ... <p>x: 44</p> <p>y: 92</p> <p>action: showParams</p> <p>controller: rails_intro</p> CS 142 Lecture Notes: Rails Controllers and Views

Controller: Compute Primes class RailsIntroController < ApplicationController def show_primes if params[:count] != nil then count = params[:count].to_i() else count = 10 end @primes = [] candidate = 2 while @primes.length < count is_prime = true @primes.each do |prime| if (candidate % prime) == 0 then is_prime = false break if is_prime then @primes << candidate candidate += 1 Query value determines # primes to compute Fill in @primes array with prime numbers CS 142 Lecture Notes: Rails Controllers and Views

Template to Display Primes <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE ...> <html ...> <head> <title><%= @primes.length %> Prime Numbers</title> <%= stylesheet_link_tag 'main' %> </head> <body> <p> The first <%= @primes.length %> prime numbers are: </p> <table class="oddEven" cellspacing="0"> <tr class="header"><td>Prime Numbers</td></tr> <% @primes.each do |prime| %> <tr class="<%= cycle('odd', 'even') %>"> <td><%= prime %></td> </tr> <% end %> </table> </body> </html> CS 142 Lecture Notes: Rails Controllers and Views

CS 142 Lecture Notes: Rails Controllers and Views Directory Structure app controllers rails_intro_controller.rb student_controller.rb views rails_intro hello.html.erb show_params.html.erb show_primes.html.erb student models assets javascripts stylesheets main.css db migrate public images CS 142 Lecture Notes: Rails Controllers and Views

Layouts app/views/layouts/application.html.erb: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title><%= @title %></title> </head> <body> <%= yield %> </body> </html> app/views/rails_intro/hello.html.erb: <% @title = "Hello, user" %> <p> This page was fetched at <%= Time.now() %> </p> CS 142 Lecture Notes: Rails Controllers and Views

CS 140 Lecture Notes: File Systems