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.

Slides:



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

23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
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.
The Web Warrior Guide to Web Design Technologies
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Tutorial 6 Working with Web Forms
Forms Review. 2 Using Forms tag  Contains the form elements on a web page  Container tag tag  Configures a variety of form elements including text.
Python and Web Programming
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
16-Jul-15 HTML. 2 What is HTML? HTML stands for Hypertext Markup Language An HTML file is a text file containing markup tags The markup tags tell the.
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Creating Web Page Forms
Forms. Form An HTML form is a section of a document containing normal content, special elements called controls (checkboxes, radio buttons, buttons, etc.),
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
XP Tutorial 6New Perspectives on HTML and XHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
1 Creating Web Forms in HTML Web forms collect information from customers Web forms include different control elements including: –Input boxes –Selection.
Server-side Scripting Powering the webs favourite services.
JavaScript, Fourth Edition
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Using Client-Side Scripts to Enhance Web Applications 1.
Website Development with PHP and MySQL Saving Data.
Week 11 Creating Framed Layouts Objectives Understand the benefits and drawbacks of frames Understand and use frame syntax Customize frame characteristics.
1 HTML Forms
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
HTML : Forms, Frames Instructor: Mr. Ahmed Al Astal ITGD4104 Department Requirement for senior student University of Palestine Faculty of IT.
ITCS373: Internet Technology Lecture 5: More HTML.
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input.
Creating Links. The Anchor Element: The anchor tag can be used in three different ways: 1.External link – to link to a web page outside your own website.
1 Building FORMS In When a visitor enters information into a web form displayed in a web browser and clicks the submit button, the information is sent.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
1 HTML forms (cont.)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
Creating Web Page Forms COE 201- Computer Proficiency.
HTML Forms. A form is simply an area that can contain form fields. Form fields are objects that allow the visitor to enter information - for example text.
AJAX. Overview of Ajax Ajax is not an API or a programming language Ajax aims to provide more responsive web applications In normal request/response HTTP.
1 Committed to Shaping the Next Generation of IT Experts. 03: Links and Forms HTML.
1 HTML Forms
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.
1 HTML forms (cont.)
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
HTML FORM. Form HTML Forms are used to select different kinds of user input. HTML forms are used to pass data to a server. A form can contain input elements.
Lesson 5 Introduction to HTML Forms. Lesson 5 Forms A form is an area that can contain form elements. Form elements are elements that allow the user to.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
Computing with C# and the .NET Framework
How to Write Web Forms By Mimi Opkins.
Play Framework: Introduction
FORMS Explained By: Sarbjit Kaur.
HTML/XHTML Forms 18-Sep-18.
Introducing Forms.
Ajax on Rails 28-Nov-18.
Forms, cont’d.
Access Lesson 2 Creating a Database
HTML Forms 18-Apr-19.
Presentation transcript:

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 with the user input action=“ URL"(required) Specifies where to send the data when the Submit button is clicked method="get" (default) Form data is sent as a URL with ?form_data info appended to the end Can be used only if data is all ASCII and not more than 100 characters method="post" Form data is sent in the body of the URL request Cannot be bookmarked by most browsers target=" target " Tells where to open the page sent as a result of the request target= _blank means open in a new window target= _top means use the same window

Ruby forms In a template, you should use form_tag() instead of The first argument is a hash that tells which action to invoke This takes the same options as url_for() – see next slide The optional second argument is another hash for setting HTML form attributes Example: :save }, { :class=>"compact" } %> …

url_for() The purpose of url_for is to avoid the need to write hardcoded URLs url_for takes a hash of options as its parameter Options include :controller, :action, and possibly :id Reasonable defaults are used You can define other options with a map.connect call in config/routes.rb (see your textbook for details) Example: url_for(:controller => "store", :action => "list") translates to your_application /store/list

Field helpers (for models) Rails provides support (in the app/helpers directory) for HTML fields text_field(:variable, :attribute, options) hidden_field(:variable, :attribute, options) password_field(:variable, :attribute, options) text_area(:variable, :attribute, options) radio_button(:variable, :attribute, tag_value, options) check_box(:variable, :attribute, options, on_value, off_value) select(:variable, :attribute, choices, options, html_options) The first argument to a helper method is the name of an instance variable (typically a model object) The second argument is an attribute of that object The first and second arguments are combined (with an underscore) to form the id of the generated field Other arguments depend on the field type For text fields, the third argument is a hash of options, for example, :size

Field helpers (for nonmodels) Rails can also support fields that have no corresponding models Names end in _tag First argument is a simple name, not an object Example syntax: text_field_tag(name, value = nil, options = { }) Example: t :size => 12) Values will be stored in the params hash when the form is submitted to the controller

Links The basic HTML link is The basic RHTML link is " method_name ") %> where method_name uses the url_for() format The basic Ajax/RHTML link is id_of_element_to_update, :url => { :action => : method_name } ) %> which refers to Original text

Responding to an Ajax link The method_name in the link_to_remote is the name of a method in the controller Since we do not want to return a complete HTML page, the named method should contain at least the following: render(:layout => false) Whatever is in the corresponding.rhtml will replace the original contents of the element

form_remote_tag() To use Ajax for any form, replace form_tag and end_form_tag with form_remote_tag and end_form_tag All form elements will be serialized and sent to the server They can be read from the params hash

Observers Observers let you call Ajax actions when the user changed data on a form Example (p. 392 in textbook): Search term: 0.5, :update => :results, :url => { :action => :search }) %>

CRUD Basic database operations are Create, Read, Update, and Delete The :scaffold method does a lot of the database work for you Scaffolds are intended to be replaced ActiveRecord::Base provides all your basic needs An ActiveRecord wraps a database; changes to the ActiveRecord result in changes to the database Each ActiveRecord object corresponds to a row in the database The attributes of the object correspond to the column in the database

Some database methods new(attributes = nil) Creates a record with the given attributes find(*args) find by id: Person.find(1) # returns the object for ID = 1 find first: Person.find(:first) # returns the first object fetched by SELECT * FROM people find all: Person.find(:all) # returns an array of objects for all the rows # fetched by SELECT * FROM people update(id, attributes) Creates a record with the given attributes destroy(id)

References Agile Web Development with Rails, by Dave Thomas and David Hansson The Ajax material is from chapter 18, “The Web, V2.0” Some of the forms information is from chapters 16 and 17 Database material from chapter 14, especially 14.5 api.rubyonrails.com Database examples from ActiveRecord::Base Some other examples from individual methods

The End