CS 142 Lecture Notes: FormsSlide 1 Simple Form Product: Price:

Slides:



Advertisements
Similar presentations
CS 142 Lecture Notes: FormsSlide 1 Simple Form Product: Price:
Advertisements

Richard Fateman CS 282 Lecture eea1 Extended Euclidean Algorithm Lecture eea.
MA/CS 375 Fall MA/CS 375 Fall 2002 Lecture 29.
CS 221 Chapter 2 Excel. In Excel: A1 = 95 A2 = 95 A3 = 80 A4 = 0 =IF(A1
CS 142 Lecture Notes: Rails Controllers and ViewsSlide 1 Simple Rails Template
Check it out! : Function Notation and Evaluating Functions.
Slide 1Fig. 22.1, p.669. Slide 2Fig. 22.3, p.670.
Slide 1Fig. 17.1, p.513. Slide 2Table 17.1, p.514.
Lectures in Microeconomics-Charles W. Upton More on Consumer Surplus.
Intelligent Information Retrieval CS 336 –Lecture 2: Query Language Xiaoyan Li Spring 2006 Modified from Lisa Ballesteros’s slides.
CS 142 Lecture Notes: FormsSlide 1 Simple Form Value1: Value2:
Lectures in Microeconomics-Charles W. Upton Consumer and Producer Surplus.
CS 142 Lecture Notes: FormsSlide 1 Draggable Rectangle #div1 { position: absolute; }...
Lectures in Microeconomics-Charles W. Upton Consumer Surplus.
Lectures in Microeconomics-Charles W. Upton Tax Rates and DWL.
CS 142 Lecture Notes: FormsSlide 1 Simple Form Value1: Value2:
This slide shows the population density of England by parish derived from the 1801 census. The slide may be used for classroom teaching and lecturing in.
CS 142 Lecture Notes: FormsSlide 1 AJAX Basics xhr = new XMLHttpRequest(); xhr.onreadystatechange = xhrHandler(); xhr.open("POST", url); xhr.send(postData);...
ADVERTISE THIS! Our Product Name: Price: Where to buy it: How to use it and good points:
ECE 8443 – Pattern Recognition EE 3512 – Signals: Continuous and Discrete Objectives: Periodic Signals Triangle Wave Other Simple Functions Review Integration.
© The McGraw-Hill Companies, Inc, 2011 Lecture Slides.
CS 142 Lecture Notes: FormsSlide 1 Simple Form Product: Price:
Fact Families. On the next 4 slides create examples of addition/subtraction fact families.
The Marketing Mix Worksheet.
Slide 1 Phishing s CS 142 Lecture Notes: Security Attacks: Phishing.
Return to Home! Go To Next Slide! Return to Home! Go To Next Slide!
Slide 1 Insert your own content.. Slide 2 Insert your own content.
Test slide upload.
Piero Belforte 1995: CSELT THRIS SLIDES
continued on next slide
Indiana U t Wendy Balmer
Sample Presentation. Slide 1 Info Slide 2 Info.
Presentation Test. Second Slide Third Slide It worked.
مهارتهای آموزشی و پرورشی ( روشها و فنون تدریس) تالیف: دکتر حسن شعبانی.
Rivier College CS575: Advanced LANs
                                                                                                                                                                                                                                                
continued on next slide
continued on next slide
پروتكل آموزش سلامت به مددجو
YG - CS170.
Elec 2607 Digital Switching Circuits
البيئة السياسية للإدارة الدولية
CS 142 Lecture Notes: Rails Controllers and Views
CS 140 Lecture Notes: Protection
HELLO THERE. THIS IS A TEST SLIDE SLIDE NUMBER 1.
Slide 1 Insert your own content.. Slide 1 Insert your own content.
Reaction time زمن الرجع.
CS-401 Computer Architecture & Assembly Language Programming
CS 140 Lecture Notes: Protection
Today’s Agenda Go over exam #2 Go over exam #3 Lab 8 for 1 hour
Slide 1 Insert your own content.. Slide 1 Insert your own content.
Slide 1 Insert your own content.. Slide 1 Insert your own content.
CS 140 Lecture Notes: Demand Paging
CS 140 Lecture Notes: Introduction
CS 140 Lecture Notes: Protection
CS-401 Assembly Language Programming
Webcast slides presentation
CS 140 Lecture Notes: Demand Paging
Objective: To know the equations of simple straight lines.
Log Structure log index term leader Server 1 command
CS 140 Lecture Notes: Protection
CS 140 Lecture Notes: Introduction
АВЛИГАТАЙ ТЭМЦЭХ ҮНДЭСНИЙ ХӨТӨЛБӨР /танилцуулга/
Exam # 1 INFORMATION Scheduled for Thursday 7/20
Chapter 2 Sets Active Learning Lecture Slides
continued on next slide
CS 250, Discrete Structures, Fall 2015 Nitesh Saxena
. ..
continued on next slide
Objective: To know the equations of simple straight lines.
Presentation transcript:

CS 142 Lecture Notes: FormsSlide 1 Simple Form Product: Price:

Slide 2 Rails Form Helpers <input id="student_name" name="student[name]“ size="30" type="text" value="Chen" /> <input id="student_birth" name="student[birth]“ size="30" type="text" value=" " /> <input name="commit" type="submit“ value="Modify Student" /> Describes type, provides initial values Object representing form

CS 142 Lecture Notes: FormsSlide 3 Customize Format...

CS 142 Lecture Notes: FormsSlide 4 Post Action Method def = Student.find(params[:id]) = = = = params[:student][:grad] then redirect_to(:action => :show) else render(:action => :edit) end Hash with all of form data Redirects on success Redisplay form on error

Security checks in Rails 4 cause update to fail CS 142 Lecture Notes: FormsSlide 5 More Compact Approach def = Student.find(params[:id]) then redirect_to(:action => :show) else render(:action => :edit) end

CS 142 Lecture Notes: FormsSlide 6 Rails 4 Pattern def = Student.find(params[:id]) params[:student])) then redirect_to(:action => :show) else render(:action => :edit) end private def student_params(params) return params.permit(:name, :birth, :gpa, :grad) end Creates new hash containing only specified elements

CS 142 Lecture Notes: FormsSlide 7 Creating New Record def = Student.new(student_params( params[:student]) then redirect_to(:action => :show) else render(:action => :edit) end

CS 142 Lecture Notes: FormsSlide 8 Validation (in Model) class Student < ActiveRecord::Base validates_format_of :birth, :with => /\d\d\d\d-\d\d-\d\d/, :message => "must have format YYYY-MM-DD" def validate_gpa if (gpa 4.0) then errors.add(:gpa, "must be between 0.0 and 4.0") end validate :validate_gpa end Custom validation method Built-in validator Saves error info

CS 142 Lecture Notes: FormsSlide 9 Error Messages :update, do |form| %>......

CS 142 Lecture Notes: FormsSlide 10 File Uploads with Rails In form post method: params[:student][:photo].read() params[:student][:photo].original_filename

CS 142 Lecture Notes: CookiesSlide 11