UC Berkeley Hello Rails. Review: MVC Goal: separate organization of data (model) from UI & presentation (view) by introducing controller –mediates user.

Slides:



Advertisements
Similar presentations
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.
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.
Chapter 15 © 2010 by Addison Wesley Longman, Inc Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in Use spread rapidly.
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
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.
XML and Ruby on Rails Jennifer Andrews LIS 531F April 25,2007.
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
LHCbPR V2 Sasha Mazurov, Amine Ben Hammou, Ben Couturier 5th LHCb Computing Workshop
MIS2502: Data Analytics MySQL and SQL Workbench David Schuff
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective,
XP New Perspectives on Microsoft Access 2002 Tutorial 71 Microsoft Access 2002 Tutorial 7 – Integrating Access With the Web and With Other Programs.
1 ADVANCED MICROSOFT WORD Lesson 15 – Creating Forms and Working with Web Documents Microsoft Office 2003: Advanced.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
A little engineering on Rails Robert W. Hasker. Goals Intro to the Rails framework ▫Basic concepts: MVC, Active Record ▫A bit of Ruby Using Rails to build.
RUBY ON RAILS CS 186 – Arsalan Tavakoli 3/18/2008 Slides adapted from CS 198 slides with the gracious permission of Armando Fox and Will Sobel.
Ruby on Rails CSCI 6314 David Gaspar Jennifer Garcia Avila.
Rails and Grails. To get started Make sure you have java installed You can get the sdk and jre at:
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
1 Dr Alexiei Dingli Web Science Stream Models, Views and Controllers.
Self Guided Tour for Query V8.4 Basic Features. 2 This Self Guided Tour is meant as a review only for Query V8.4 Basic Features and not as a substitute.
Introducing Access Lesson 1. Objectives Start Access and explore the Database window Explore database objects Enter, edit, and delete records in a datasheet.
Part 06 – A More Complex Data Model Entity Framework and MVC NTPCUG Tom Perkins.
UC Berkeley More Rails: ActiveRecord, ActionController, ActionView, and if time, Associations.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Lecture 10 Rails Projects Topics SaaSSaaS Readings: SaaS book Ch 2, 4 February 24, 2014 CSCE 740 Software Engineering.
® Microsoft Access 2010 Tutorial 1 Creating a Database.
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
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.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
Lecture 11 Rails Topics SaaSSaaS Readings: SaaS book Ch February CSCE 740 Software Engineering.
Associations INFO 2310: Topics in Web Design and Programming.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
THE WEBMASTERS: SENG + WAVERING.  On account of construction, we will be having class in room 1248 next week.
Date : 3/04/2010 Web Technology Solutions Class: PHP Web Application Frameworks.
1 Dr Alexiei Dingli Web Science Stream Installing ROR.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
Rails and routing INFO 2310: Topics in Web Design and Programming.
Introduction to information systems RUBY ON RAILS dr inż. Tomasz Pieciukiewicz.
LIS654 lecture 4 more on omeka Thomas Krichel
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
MYSQL AND MYSQL WORKBENCH MIS2502 Data Analytics.
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
Schoolwires How to modify your classroom webpage.
Beginning Fare File Management Hudson Fare Files 104 – Rev. 8/15 Point to Point (PTP)
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
Perform a complete mail merge Lesson 14 By the end of this lesson you will be able to complete the following: Use the Mail Merge Wizard to perform a basic.
Cake PHP – OOPS approach for PHP
Web Technology Solutions
Databases and the MVC Model
Oracle Application Express (APEX)
Accsess 2013 Creating Database.
mysql and mysql workbench
CMPE 280 Web UI Design and Development October 24 Class Meeting
…and web frameworks in general
Ruby on Rails by Manik Juneja
Ruby on Rails by Manik Juneja
Developing a Model-View-Controller Component for Joomla Part 3
MIS2502: Data Analytics MySQL and SQL Workbench
Databases and the MVC Model
Databases and the MVC Model
…and web frameworks in general
Tutorial 7 – Integrating Access With the Web and With Other Programs
SQL Server Fundamentals for Beginners
Navigating SSMS Primer for Beginners
Presentation transcript:

UC Berkeley Hello Rails

Review: MVC Goal: separate organization of data (model) from UI & presentation (view) by introducing controller –mediates user actions requesting access to data –presents data for rendering by the view Web apps are “sort of” MVC by design Controller ViewModel User actions Directives for rendering data Read data Update data Data provided to views.rb (Ruby) code.rhtml template (or.rjs,.rxml...) SQL table + Ruby class

What rails appname does Once you install Rails... –cd somewhere –say rails appname –make sure your ISP has configured Apache to understand where Rails CGI dispatcher is app/, where the action is –especially models, view, controllers script/, useful scripts to help develop your app test/ structure built right in! We’ll meet it later

A truly trivial Hello World app The Student Finder app Download from class Web page (tgz, zip) Unzip into your development directory (you'll get a student_finder subdir) Fire up the app and point your browser at it Let’s take a tour –controller...view...parameters...routes

What about our trivial hello world? It manipulates no data models –though arguably this is where much of the strength of RoR lies One controller (welcome_controller.rb) One view What’s the life cycle of a request, vis-a-vis the MVC model and Rails?

Test your app Go to the test/ subdir in $APP_ROOT say rake test What happened? –Where did the “dummy” tests come from? –Why doesn’t your database get screwed up?

A Less Trivial Example... Let’s walk through a full (single-table) MVC example... 1.Design the model 2.Instantiate the model (table & Ruby code) 3.Basic controller to do CRUD (Create, Read, Update, Destroy) operations on model

SQL 001 A SQL table has a number of rows of identical structure Each row has several columns (fields, attributes, etc.) You can define relationships between tables (associations)—we’ll get to that later A collection of tables & relationships is called a schema

Preview: CRUD in SQL 4 basic operations on a table row: Create, Read, Update attributes, Destroy INSERT INTO students (last_name, ucb_sid, degree_expected) VALUES (“Fox”, 99999, “ ”), (“Bodik”, 88888, “ ”) SELECT * FROM students WHERE (degree_expected < “ ”) UPDATE students SET degree_expected=“ ” WHERE last_name=“Bodik”) DELETE FROM students WHERE ucb_sid=99999

Rails ActiveRecord models ActiveRecord, a major component of Rails... –Uses SQL tables as underlying storage, and SQL commands as underlying manipulation, of collections of Ruby objects –(Later) Provides an object-relationship graph abstraction using SQL Joins as the underlying machinery Oversimplification: 1 instance of Ruby class Foo == 1 row in a SQL table called Foos Let Rails do the work of creating our model and related stuff: script/generate scaffold student last_name:string first_name:string ucb_id:integer degree_expected:datetime

Creating the Students table We’re not done yet! Students table doesn’t exist...so let’s define a student –edit the migration file 001_create_students.rb –give each student a first & last name, UCB ID, degree date Let Rails do the work of interacting with the database: rake db:migrate Question: what database?

Exploring the app Let’s walk around the app a little... –Create a new student –Read (show) a student, or lis all students –Update a student’s info –Destroy a student (!) What’s find, respond_to, form_for ?

MVC in RoR: Convention over Configuration If data model is called Student: model (Ruby class) is app/models/student.rb SQL table is students –table row = object instance –columns = object methods (a/k/a object instance variables) controller methods live in app/controllers/student_controller.rb views are app/views/student/*.erb.html –and other types of views we'll meet later

Capture common elements of student-related views CRUD views For creating test cases on student model & controller More to notice about scaffolding identical app/models/student.rb create test/unit/student_test.rb create test/fixtures/students.yml create app/views/students/_form.rhtml create app/views/students/list.rhtml create app/views/students/show.rhtml create app/views/students/new.rhtml create app/views/students/edit.rhtml create app/controllers/students_controller.rb create test/functional/students_controller_test.rb create app/helpers/students_helper.rb create app/views/layouts/students.rhtml create public/stylesheets/scaffold.css

Recap CRUD, the four basic operations on database rows ActiveRecord, a library that arranges to “map” your models into database rows scaffolding gets your app off the ground early, then you can selectively replace it –captures common model of a Web front-end to CRUD operations convention over configuration makes both of the above tractable to implement while saving you work

Lab 1: add features to student_finder app “Search by last name” feature where result screen lets you click through to Edit –Requires changes to List view and some controller changes “Inactive” database column for students who’ve left the University –Hint: use migrations, don’t modif DB directly! –Extra credit: check box for Search function “restrict to active students only” Hint: use :conditions option of ActiveRecord#find New courses model with basic CRUD –Hint: requires a migration, a model file, a controller, and views