Create, Update and Delete Carol Wolf Computer Science.

Slides:



Advertisements
Similar presentations
1.NET Web Forms DataGrid © 2002 by Jerry Post. 2 Data Grid Has Many Uses  The grid uses HTML tables to display multiple rows of data. It is flexible.
Advertisements

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.
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.
The Initiative For School Empowerment and Excellence (i.4.see) “Empowering teachers, administrators, policy makers, and parents to increase student achievement.”
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.
Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Create Forms Lesson 5. Software Orientation Creating Forms A form is a database object –enter, edit, or display data from a table or query Providing.
Faculty Manager An ACEware Webinar. In this webinar... Adding and Maintaining a Faculty Record Faculty Mgr Preferences & UDF’s Storing a faculty resume.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
UNESCO ICTLIP Module 4. Lesson 4 Database Design, and Information Storage and Retrieval Lesson 4. Advanced features of WinISIS.
Server-side Scripting Powering the webs favourite services.
KJOlinski.com - RapidHMI INTRODUCING RapidHMI AND PLCExplorer.
CSCI 6962: Server-side Design and Programming Support Classes and Shopping Carts.
Lesson No:9 MS-Word Tools, Mail Merge and working with Tables CHBT-01 Basic Micro process & Computer Operation.
Creating a Web Site to Gather Data and Conduct Research.
Databases. Database A database is an organized collection of related data.
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.
1 Dr Alexiei Dingli Web Science Stream Helpers, Forms and Layouts.
PHP meets MySQL.
Eurotrace Hands-On The Eurotrace File System. 2 The Eurotrace file system Under MS ACCESS EUROTRACE generates several different files when you create.
Forms Carol Wolf Computer Science. The Controller  To create a controller, type  rails generate controller pizza index order  This creates a controller.
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.
1 OPOL Training (OrderPro Online) Prepared by Christina Van Metre Independent Educational Consultant CTO, Business Development Team © Training Version.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
Computer Literacy BASICS: A Comprehensive Guide to IC 3, 5 th Edition Lesson 24 Managing and Reporting Database Information 1 Morrison / Wells / Ruffolo.
Ruby on Rails CSE 190M, Spring 2009 Week 6. Overview How to use a database Demo creating a blog application on Rails Explain how the application works.
Basic & Advanced Reporting in TIMSNT ** Part Two **
1 Dr Alexiei Dingli Web Science Stream A ROR Blog.
Diagnostic Pathfinder for Instructors. Diagnostic Pathfinder Local File vs. Database Normal operations Expert operations Admin operations.
Creating PHPs to Insert, Update, and Delete Data CS 320.
1 Dr Alexiei Dingli Web Science Stream A ROR Twitter.
® Microsoft Office 2013 Access Creating a Database.
What have we learned?. What is a database? An organized collection of related data.
Access Forms and Queries. Entering Data in Your Table  You can add data to your table in Datasheet view, by typing in the columns and rows.  This.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
V 1.0Slide 1 Staff - Training Information Click “Add” button to add a training record.
Build a database V: Create forms for a new Access database Overview: A window into your data So far in this series of courses, you’ve built tables, relationships,
1 School Information Systems SISFin and P-Card. 2 Benefits of P-Card P-Card is a credit card and can be used with any merchant who accepts them. Purchases.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
Learning to use the Interactive Online Classroom Classroom Activities.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
A user guide to accessing, reviewing and contributing to the Online Registry System.
Microsoft Access Introduction. What is a database? A DATABASE is a collection of related data.
© 2007 by Prentice Hall2-1 Introduction to Oracle 10g Chapter 2 Overview of SQL and SQL*Plus James Perry and Gerald Post.
Rails and routing INFO 2310: Topics in Web Design and Programming.
ASSIGNMENT 2 Salim Malakouti. Ticketing Website  User submits tickets  Admins answer tickets or take appropriate actions.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
Module Road Map The Scope of the Problem A range of potential problems Lost Updates User A reads a record User B reads the same record User A makes changes.
The Controller Carol Wolf Computer Science. Rails generate commands  Using the generate command, you can create a number of useful objects.  Rails:
DATA MANAGEMENT AND DATABASES. Data Management Data management is the process of controlling the information generated during a research project or transaction.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
Routes Carol Wolf Computer Science. RESTful Architecture  Rails uses REST-style architecture: representation state transfer  resources :courses in routes.rb.
MVC Controllers TestsMigrations Ye Olde Internet Model DB Server Router View Browser Today’s focus Controller.
Y.-H. Chen International College Ming-Chuan University Fall, 2004
Creating Data Base & Sql Data Source
Active Server Pages Computer Science 40S.
Play Framework: Introduction
Access Creating a Database
Access Creating a Database
Access Lesson 2 Creating a Database
What is a Database? A collection of data organized in a manner that allows access, retrieval, and use of that data.
Model – View – Controller Pattern
Creating Data Base & Sql Data Source
MVC Controllers.
WJEC GCSE Computer Science
Presentation transcript:

Create, Update and Delete Carol Wolf Computer Science

Basic operations on databases  Create – Add a new table to the database  Read – List all objects in a table or find a specific one  Update – Change one or more fields in an object  Delete – Remove an object from the table  Requests and responses are the usual ERB files.  Controller code is somewhat complicated, particularly for update.  You can generate new controller methods and ERB files using rails generate controller … -s.  The –s tells Rails to skip existing methods.

Create  To add a create method to the controller, type rails generate controller schedule new_course show_course –s  This does not get a new controller. Instead it adds two new methods as well as generating new views.  Create requires two methods, one to show a form that will collect the data for the new object and a second to add the result to the database table.  It also adds two new routes to routes.rb. They must both be changed to posts.  The code for the index file only has to send the user to the server.

index.html.erb Add a Course {:action => :new_course} do |form| %>  Because there is a button, the method is ‘post’. The action gives the name of the controller method, here new_course.

The controller method new_course def new_course respond_to do |format| format.html # new_course.html.erb end End  This just sends a view to the user with text fields for entering the data.  The view, new_course.html.erb, contains an action that sends the data to the controller method, create_course.

new_course.html.erb New course {:action => :create_course} do |f| %> Number: Name: Credits:

The controller method create_course def = Course.new(params[:course]) respond_to do |format| flash[:notice] = 'The course was successfully created.' format.html { render :action => "show_course" } else flash[:notice] = 'Error: The course was not created.' format.html { render :action => "new_course" } end

show_course.html.erb Number: Name: Credits:

Update  The only tricky part in update is using the id that is automatically generated by Rails to keep track of the object.  Using it allows us to make changes to all the fields.  Since it is not of interest to the user, it is stored in a hidden field.  But since it is one of the parameters, it can be used to store the record back in the database.  We begin, as before, by generating new methods for the controller and views.

The index file Update a Course {:action => :edit_course} do |form| %> Course Number: 10 %>

The controller - update def = = == nil flash[:notice] = 'The course was not found.' redirect_to(:action => "not_found" ) end

edit_course.html.erb Editing course {:action => :update_course} do |f| %> Number: Name: Credits:

The controller – update_course def = params[:course] = Course.find_by_id(id) respond_to do |format| flash[:notice] = 'Course was successfully updated.' format.html { render :action => "show_course"} else flash[:notice] = 'Course was not updated.' format.html { render :action => "edit_course" } end

Delete  When deleting an object, the user should be given a chance to view it and decide if it should go.  This can be done using confirm. This was done in the index file generated by the scaffold command.  Another way is just to give the user a choice of deleting the object or returning to the mail page without making a change.

Delete – index.html.erb Delete a course {:action => :delete_course} do |form| %> CRN: 10 %>

The controller – delete_course def = = != nil respond_to do |format| format.html end else flash[:notice] = 'The course was not found.' end

delete_course.html.erb Delete Course {:action => :remove_course} do |f| %> Number: Name: Credits:

The controller - remove_course def = End  Response – remove_course.html.erb The course was removed.