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.

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
NIMAC 2.0: The Accessible Media Producer Portal NIMAC 2.0 for AMPs.
Introduction to ReportSmith and Effective Dated Tables
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 Collections Keeper A collections management system Brian J. Mullen.
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
1 Chapter 12 Working With Access 2000 on the Internet.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
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.
Project Implementation for COSC 5050 Distributed Database Applications Lab6.
Creating Tables in a Web Site Using an External Style Sheet HTML5 & CSS 7 th Edition.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
CS378 - Mobile Computing Persistence - SQLite. Databases RDBMS – relational data base management system Relational databases introduced by E. F. Codd.
Project Implementation for COSC 5050 Distributed Database Applications Lab5.
Refworks Presented by Margaret Clark, Reference Librarian FSU College of Law Library September 20, 2005.
Some Basic Database Terminology
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Informer Web Reporting Basic Reporting
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Using Dreamweaver. Slide 1 Dreamweaver has 2 screens that do different things The Document window where you create your WebPages The Site window where.
Searching UCN Databases Finding Journal Articles Through Ebsco.
Project Implementation for COSC 5050 Distributed Database Applications Lab2.
Server-side Scripting Powering the webs favourite services.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Introducing.
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.
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,
PHP meets MySQL.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
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.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Basic & Advanced Reporting in TIMSNT ** Part Two **
9 Persistence - SQLite CSNB544 Mobile Application Development Thanks to Utexas Austin.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Creating PHPs to Insert, Update, and Delete Data CS 320.
BIT 286: Web Applications Lecture 10 : Thursday, February 5, 2015 ASP.Net Form Submission.
CSCI 3327 Visual Basic Chapter 13: Databases and LINQ UTPA – Fall 2011.
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.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
Create, Update and Delete Carol Wolf Computer Science.
BlackBerry Applications using Microsoft Visual Studio and Database Handling.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
>> PHP: File Uploads. Pre-requisite Go Online – Download file modify-item.php – copy it to your root folder (D:\xampp\htdocs\Buy4mMe) Web-Based Systems.
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:
SQL Query Analyzer. Graphical tool that allows you to:  Create queries and other SQL scripts and execute them against SQL Server databases. (Query window)
Migrations Carol Wolf CS 396X. ISBNTitleAuthorImage EmmaAustenemma.jpg Oliver TwistDickenstwist.jpg HamletShakespearehamlet.jpg.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
This is the software we will use to load our html page up to the server. You can download a copy for home if you want to.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
Routes Carol Wolf Computer Science. RESTful Architecture  Rails uses REST-style architecture: representation state transfer  resources :courses in routes.rb.
Play Framework: Introduction
Database application MySQL Database and PhpMyAdmin
Access Lesson 1 Understanding Access Fundamentals
Model – View – Controller Pattern
Presentation transcript:

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 controller librarian  This creates  librarian_controller.rb in the controllers folder  librarian_helper.rb in the helpers folder  Folder called views/librarian folder  Controller file contains class LibrarianController < ApplicationController end  The views folder is empty.

Views page we want to create

Index.html.erb  The easiest way to create an erb file is to copy one generated by the scaffold command, rename it if needed and modify it.  Here we can use index.html.erb in the views/books folder Listing books …  Change the heading to Librarian and one by one, fill in the parts of the table.

CRUD – Create, Read, Update, Delete  Create – add a new item to the database  Read – list all items in the database or find a particular one.  Update – change the data in a row or rows of the database.  Delete – remove an item from the database (also called destroy.)

Erb code to list all books or find a book. List all books {:action => :list_books} do |form| %> Find a book {:action => :find_book} do |form| %> Title: 20 %>

class LibrarianController < ApplicationController def index end def = Book.find_books end def = = respond_to do |format| != nil format.html else flash[:notice] = 'Book was not found.' format.html { render :action => "index" } end

Create a new row in the database  Ruby =  Code for index page Create a book {:action => :new_book} do |form| %> Controller code is in new_book and create_book.

def new_book respond_to do |format| format.html # Send new_book.html.erb to the client. end def = Book.new(params[:book])# Get a new book with the parameters. respond_to do |format| Save the book in the database. flash[:notice] = 'The book was successfully created.' format.html { render :action => "show_book" } else flash[:notice] = 'Error: The book was not created.' format.html { render :action => "new_book" } end

Web page for new_book New book {:action => :create_book} do |f| %> ISBN: Author: Title: Image:

Creating the new row  Client clicks on Create a book on the index page.  The action in the form is new_book.  The new_book method in the controller sends the web page new_book.html.erb to the client. It collects the information about the new book.  The action in the form is create_book.  This activates the create_book method in the controller.  The controller creates a new book with the parameters = Book.new(params[:book])  If the book is saved in the database, the controller sends the web page, show_book.html.erb, back to the client.

Update a row of the database  If the client clicks on update and supplies an id (isbn), the edit_book method in the controller is executed. def = = end  This method finds the book in the database (if it’s there) and stores the data in the  This data is used to populate a form, edit_book.html.erb, that is returned to the client.  The client can then change the data in the form and submit the result to the controller.

Update_book page {:action => :update_book} do |f| %> ISBN: Author: Title: Image:

Hidden field  The update_book.html.erb page has a hidden field.  The controller will fill in this field with the id that was automatically generated when the table row was created, but it will not show the id to the client.  This id can be used to save the modified row to the table rather than the isbn or some other field.  The advantage to doing this is that all the displayed fields can be changed, since none of them are the primary key. A primary key cannot be altered.

Controller method, update_book def = params[:book] id the id from the = Book.find_by_id(id)#Find the book using the id. respond_to do |format| flash[:notice] = 'Book was successfully updated.' format.html { render :action => "show_book"} else flash[:notice] = 'Book was not updated.' end

Rails commands in controller method  You can find a row in a database table using any of the fields. This one uses the id, which was in the hidden = Book.find_by_id(id)  The rails command to update a row in the table  This is much simpler to write than the SQL that rails translates it to.

Page returned to the client after changes Book Data ISBN: Author: Title: Image:

Deleting a row of the database table  To delete a row, first get the data and display it for the client.  Next ask the client to confirm that this is the row to be removed.  If the client confirms that it should be deleted, remove it from the table. def = end  If the client decides not to remove it, return to the index page.

Web page to delete a row of the table Delete Book {:action => :remove_book} do |f| %> ISBN: Author: Title: Image: