Model – View – Controller Pattern

Slides:



Advertisements
Similar presentations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Using Perl for CGI Programming.
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.
Adding Dynamic Content to your Web Site
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.
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 1 Simple Rails Template
Ruby on Rails by Manik Juneja Ruby On Rails. Ruby on Rails by Manik Juneja Rails is a Web Application development framework. Based on the MVC pattern.
CS 683 Emerging Technologies Fall Semester, 2005 Doc 25 Rails Transactions, Sessions, Filters Nov 29, 2005 Copyright ©, All rights reserved SDSU.
What is it? –Large Web sites that support commercial use cannot be written by hand What you’re going to learn –How a Web server and a database can be used.
XML and Ruby on Rails Jennifer Andrews LIS 531F April 25,2007.
15-Jun-15 Rails and Ajax. HTML Forms The... tag encloses form elements (and usually includes other HTML as well) The arguments to form tell what to do.
1 Cleaning up the Internet Using AJAX, SOAP and Comet CS526 Mike Gerschefske Justin Gray James Yoo 02 May 2006.
CS 683 Emerging Technologies Fall Semester, 2005 Doc 23 Rails Model Example Nov 17, 2005 Copyright ©, All rights reserved SDSU & Roger Whitney, 5500.
Methods for Rails. File Structures This is taken directly from app Holds all the code that's specific.
Multiple Tiers in Action
CS 638 Web Programming Lifecycle examples Supplement to segment 4.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Intro to Rails INFO 2310: Topics in Web Design and Programming.
Chapter 9 Using Perl for CGI Programming. Computation is required to support sophisticated web applications Computation can be done by the server or the.
Web Application Programming Carol Wolf Computer Science.
Why rails? Carlos Kirkconnell. Google Happiness leads to Productivity Happiness Matters.
Views Carol Wolf Computer Science. Extended Ruby  Views files are written in extended Ruby, erb.  They end in.html.erb.  Ruby code is intermixed with.
M1G Introduction to Database Development 6. Building Applications.
USING PERL FOR CGI PROGRAMMING
Ruby on Rails Your first app. Rails files app/ Contains the controllers, models, views and assets for your application. You’ll focus on this folder for.
CA Professional Web Site Development Class 2: Anatomy of a Web Site and Web Page & Intro to HTML.
1 Dr Alexiei Dingli Web Science Stream A ROR Blog.
1 Dr Alexiei Dingli Web Science Stream A ROR Twitter.
InfoBox A Personal Information Manager Built with Ruby on Rails Dustin Martin.
Connie Rogers LIS 764 Fall is a free bibliography composer helps you generate, edit and publish a works cited list guides you through punctuation.
Routes & REST & URL-helpers & validations & filters
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
RUBY ON RAILS (RoR) Ishwor Khadka. Why Ruby on Rails?
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
Producing a high-impact web experience by integrate Macromedia Flash and ASP By Katie Tuttle CS 330: Internet Architecture and Programming Project.
Create, Update and Delete Carol Wolf Computer Science.
Adapted from  2012 Prentice Hall, Inc. All rights reserved. 5 th ed: Chapter 2 and th ed: 4.11 SY306 Web and Databases for Cyber Operations.
CSCI-235 Micro-Computers in Science The Internet and World Wide Web.
Rails and routing INFO 2310: Topics in Web Design and Programming.
How Web Database Architectures Work CPS181s April 8, 2003.
AJAX in Ruby-on-Rails. Ruby on Rails and AJAX AJAX can be done with just Javascript Easier if you use libraries –Prototype –SAJAX –jQuery Libraries only.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
The Controller Carol Wolf Computer Science. Rails generate commands  Using the generate command, you can create a number of useful objects.  Rails:
Migrations Carol Wolf CS 396X. ISBNTitleAuthorImage EmmaAustenemma.jpg Oliver TwistDickenstwist.jpg HamletShakespearehamlet.jpg.
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.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
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.
Routes Carol Wolf Computer Science. RESTful Architecture  Rails uses REST-style architecture: representation state transfer  resources :courses in routes.rb.
Agile Web Development with Rails, Chapter 11: Task F: Add a Dash of Ajax David Grayson Based on the book by Sam Ruby. Las Vegas Ruby Meetup,
Web Systems & Technologies
Rails web application framework that uses Ruby as its programming language builds skeleton applications for you applications come with lots of defaults.
Warm Handshake with Websites, Servers and Web Servers:
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
Web Software Model CS 4640 Programming Languages for Web Applications

PHP / MySQL Introduction
PHP: Output Formatting
Ruby on Rails by Manik Juneja
(Advanced) Web Application Development
Web Browser server client 3-Tier Architecture Apache web server PHP
Ruby on Rails by Manik Juneja
Chapter 15 Introduction to Rails.
Unit 1 The Web Book Test.
Back end Development CS Programming Languages for Web Applications
DR. JOHN ABRAHAM PROFESSOR UTPA
CMPE/SE 131 Software Engineering February 9 Class Meeting
Client-Server Model: Requesting a Web Page
Your computer is the client
Back end Development CS Programming Languages for Web Applications
Presentation transcript:

Model – View – Controller Pattern Carol Wolf CS 396X

Models ## A class to work with the database class Book < ActiveRecord::Base def self.find_books find(:all, :order => "author") end   def self.find_a_book(title) @book = find_by_title(title)

Controllers Classes with methods that receive requests from the client, query the database (through the model) and then respond back to the client. These are subclasses of the ApplicationController class. Controllers are the most complicated classes in Rails and do the most work.

class LibrarianController < ApplicationController def index end def list_books @books = Book.find_books def find_book @params = params[:book] @book = Book.find_a_book(@params[:title]) respond_to do |format| if @book != nil format.html else flash[:notice] = 'Book was not found.' format.html { render :action => "index" }

Views – Request Page Views are the web pages sent to the client. They are written in a combination of html and ERB, embedded Ruby. Views come in pairs, the request page that the client sends to the server and the response page that the server sends back. <h1>Librarian</h1> <h2>List all books</h2> <h3><% form_for :book, :url => {:action => :list_books} do |form| %> <p><%= submit_tag "List Books" %></p> </h3> <% end %>

Views – Response Page <h1>List of Books</h1> <table> <tr> <th>ISBN</th> <th>Author</th> <th>Title</th> </tr> <% for book in @books %> <td><%=h book.isbn %></td> <td><%=h book.author %></td> <td><%=h book.title %></td> <% end %> </table> <br /> <%= link_to 'Back', '/librarian' %>

Request and Response Pages