MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.

Slides:



Advertisements
Similar presentations
PHP + Framework + MVC. What is Framework? Common code - Generic functionality Extensible - Specific functionality Unlike library – Flow Dictated by.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
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.
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.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
DT228/3 Web Development multi page applications/ sharing data.
Visual Web Information Extraction With Lixto Robert Baumgartner Sergio Flesca Georg Gottlob.
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.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Methods for Rails. File Structures This is taken directly from app Holds all the code that's specific.
Software Architecture Patterns (2). what is architecture? (recap) o an overall blueprint/model describing the structures and properties of a "system"
Attribute databases. GIS Definition Diagram Output Query Results.
Creating a wiki blog. Run apps that come with instant rails distribution select I /rails applications/open ruby console window Cd to cookbook or typo.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Overview of Framework by Ahamed Rifaudeen A. page - i Steps before entering into the Framework?  Basic knowledge of object-oriented programming (OOP)
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Ruby on Rails. What is Ruby on Rails? Ruby on Rails is an open source full-stack web framework. It is an alternative to PHP/MySQL. It can render templates,
1 Dr Alexiei Dingli Web Science Stream Models, Views and Controllers.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Server-side Scripting Powering the webs favourite services.
What is Sure BDCs? BDC stands for Batch Data Communication and is also known as Batch Input. It is a technique for mass input of data into SAP by simulating.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
1 An Introduction to the Development of Web Applications using Ruby on Rails with Ajax Ansgar Berhorn, B.Sc. and Mike Rowe, Ph.D.
1 Dr Alexiei Dingli Web Science Stream Helpers, Forms and Layouts.
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
Lecture 10 Rails Projects Topics SaaSSaaS Readings: SaaS book Ch 2, 4 February 24, 2014 CSCE 740 Software Engineering.
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
COMP3121 E-Commerce Technologies Richard Henson University of Worcester November 2011.
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.
AUTOMATION OF WEB-FORM CREATION - KINNERA ANGADI – MS FINAL DEFENSE GUIDANCE BY – DR. DANIEL ANDRESEN.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
Lecture 11 Rails Topics SaaSSaaS Readings: SaaS book Ch February CSCE 740 Software Engineering.
JSTL Lec Umair©2006, All rights reserved JSTL (ni) Acronym of  JavaServer Pages Standard Tag Library JSTL (like JSP) is a specification, not an.
The Active Record Paradigm Databases in Database-Centric Web Site Development.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Ruby on Rails: Databases. Rails Database Familiar Table Concept Naming convention – lower case, plural (i.e. tweets) How to Access (find), Update, Delete.
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
Architectural Patterns Support Lecture. Software Architecture l Architecture is OVERLOADED System architecture Application architecture l Architecture.
Google App Engine Data Store ae-10-datastore
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
How to Build an IT Portal with Oracle Application Server Allan L Haensgen Senior Principal Instructor Oracle Corporation Session id:
JAVA BEANS JSP - Standard Tag Library (JSTL) JAVA Enterprise Edition.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
 Shopping Basket  Stages to maintain shopping basket in framework  Viewing Shopping Basket.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
RESTful Web Services What is RESTful?
MVC WITH CODEIGNITER Presented By Bhanu Priya.
Rails and routing INFO 2310: Topics in Web Design and Programming.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
® IBM Software Group © 2007 IBM Corporation Module 3: Creating UML Diagrams Essentials of Modeling with IBM Rational Software Architect, V7.5.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Navigation Framework using CF Architecture for a Client-Server Application using the open standards of the Web presented by Kedar Desai Differential Technologies,
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.
Apache Struts Technology A MVC Framework for Java Web Applications.
MVC Architecture, Symfony Framework for PHP Web Apps
Software Design.
Server Concepts Dr. Charles W. Kann.
PHP Training at GoLogica in Bangalore
MVC Framework, in general.
Ruby on Rails by Manik Juneja
Ruby on Rails by Manik Juneja
Chapter 15 Introduction to Rails.
DATABASES WHAT IS A DATABASE?
Model View Controller (MVC)
Presentation transcript:

MVC & ActiveRecord by Christian Mohr & Mohamed Souiai

Content MVC ActionController ActionView ActiveRecord Routing

Model View Controller Architectural pattern for interactive Applications. Isolates business logic from user interface consideration. Grants flexibility modularity reusability of Objects.

Model In general the model represents the information (the data) of the application and the business rules used to manipulate the data. Inside Ruby on Rails the ActiveRecord Module corresponds to the model in the MVC paradigm.

View In general the view corresponds to elements of the user interface such as text, checkbox items. In Rails the ActionView is used to create Templates and visualizes the data provided by the controller, in different formats.

Controller In general the controller manages details involving the communication to the model of user actions such as keystrokes and mouse movements. In Rails the Controller is realized by the ActionController who coordinates the interaction between user and Application.

A simple bookmark projekt In the following slide we introduce the MVC paradigm in the context of Ruby on rails.

Control center ActionController Tasks: Receiving Http-Request data (i.e. Form data) Database requests via model-classes. Setting and query of cookies and sessions. Setting flash messages. Calling templates. Forwarding Files and data. Authentication.

Control center ActionController Our Controller class inherits from the ApplicationController. Class AirportsController < ApplicationController UML Diagram:

Control center ActionController Controller generator: Syntax: ruby script/generate controller name [action_1 … action_N] Generates the controller app/controllers/ name _controller.rb with optional actions and ActionViews: app/views/ name / action_n.html.erb. The Actions can be added manually. In that case, the corresponding views are not generated automatically. 1,2

Control center ActionController Controller Actions: The public Methods of the Controller Access via URL call: : / / 3,4,5

ActionView Template-File containing Ruby- and HTML- Code. By Convention, the name is the same as the corresponding action. All View-Files have the extension. html.erb

ActionView Syntax in ActionView Files Ruby Code: Ruby Output: By using html_escape(…) or h(…) Tag-specific characters (i.e. and &) are masked.

ActionView Instance variables: Variables with a leading ’ are accessible to all methods inside the defining controller and the corresponding views.

ActiveRecord … treating Data from a Database like Objects Domain Specific Language (DSL) “ActiveReord” Design pattern by Martin Fowler: Mapping object-oriented Data to relational Data and vice versa.

ActiveRecord Models: Classes, that represent a data- table and are responsible for the database operations (CRUD) Each row in the database represents a model-object

ActiveRecord Model-Generator Syntax: ruby script/generate model modelname Generates the ActiveRecord model file app/models/ modelname.rb To create a new Row in the data table, we create a new Object of the class modelname. By Convention, the data table name is lower case and plural and the model class name is in singular with upper case initial. 6

ActiveRecord CRUD (Create, Read, Update Delete) The four basic database operations: Create create a new dataset Readread a dataset Updatealter an existing dataset Deletedelete a dataset

ActiveRecord ActiveRecord-Classes provide methods for the following basic database operations: newcreates a new ActiveRecord-Object Create(…)creates and saves a new AR-Object Find(ID)finds the correspoding dataset Find(:all, :conditions=>…) It is possible to add custom methods. 7,8

ActiveRecord ActiveRecord-Objects offer the following methods: savesaving an object to the database updatealter all or single object attributes destroydelete an object

ActiveRecord Interesting Functions: Validation Before- and After-Filter Associations and Relations Migrations Transactions Automatic attributes (created_at, updated_at)

ActiveRecord Oracle PostgreSQL SQLite Sybas Supported relational management database systems DB2 Firebird Frontbase MySQL Openbase

Routing Defines which internal controller and action should be called depending on the URL. Routing rules are stored in config/routes.rb Auto generated entries: ActionController::Routing::Routes.draw do |map| #... map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end Restart the server after changing the Routing!

Routing Routing Diagram

Routing Links To generate a Link to The code in the View would look like this: 'bookmarks', :action => "show", :id => 1 %> There are ways to simplify this!

Routing Simplified URL’s using map.connect Given Routing: Desired URL: Add routing-entry above standard entries: map.connect 'login', :controller => "authentication”, :action => "login"

Routing Named Routes using map.name Add routing-entry above standard entries: map.login 'login', :controller => "authentication", :action => "login" Provides login_url and login_path name_urlcontains absolute path incl. host name_pathcontains relative path without host.

Routing root routeusing map.root An applications default index page URL: If no controller provided (i.e. the default rails welcome-page is displayed changing config/routes.rb entry to map.root :controller => "bookmarks” makes bookmarks the root controller Make sure to delete homonymous files in pubic/

Routing Also possible: Complex routing with regular expressions Routing with defined HTTP-Method (GET, POST, PUT, DELETE)

The end Thank you for listening.