1 Dr Alexiei Dingli Web Science Stream Helpers, Forms and Layouts.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
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.
Layout using CSS. Using multiple classes In the head:.important{font-style:italic;}.title{color:red;} In the body: Here's a type of paragraph that is.
HTML – A Brief introduction Title of page This is my first homepage. This text is bold  The first tag in your HTML document is. This tag tells your browser.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
CS3L: Introduction to Symbolic Programming Summer 2008 Gilbert Chou Bonus Lecture: Web Programming.
4.01 Cascading Style Sheets
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.
TECH2018 Multimedia and the Internet More about CSS and Page Layouts.
Structure Content Presentation Semantics.
 2002 Prentice Hall. All rights reserved. JavaServer Pages.
Drboots presents. Web 101 Utility links | Join SWIFT | Pylons Navigation links Some place Another place Links Nothinghere Content goes here This is content…seriously.
Structure Content Presentation Semantics.
Microsoft Expression Web - Illustrated Unit B: Creating a Web Site.
Chapter 4 HTML. Objectives Explain how HTML/XHTML are used and describe the difference between them Interpret HTML code Explain how HTML Forms are used.
1 Dr Alexiei Dingli Web Science Stream Models, Views and Controllers.
Web Development & Design Foundations with XHTML
 HTML stands for Hyper Text Mark-up Language. The coding language used to create documents for the World Wide Web  HTML is composed of tags. HTML tags.
Using Html Basics, Text and Links. Objectives  Develop a web page using HTML codes according to specifications and verify that it works prior to submitting.
XHTML Instructor: Charles Moen CSCI/CINF XHTML  A stricter version of HTML  Extensible HTML  The XHTML specification is maintained by the World.
Copyright © Terry Felke-Morris CSS Flow & Positioning 1 Copyright © Terry Felke-Morris.
>> Introduction to HTML: Tags. Hyper - is the opposite of linear Text – words / sentences / paragraphs Mark-up – Marking the text Language – It is a language.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
CIS67 Foundations for Creating Web Pages Professor Al Fichera Rev. September 14, 2010—All HTML code brought to XHTML standards. Reference for CIS127 and.
MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.
1 Dr Alexiei Dingli Web Science Stream Advanced ROR.
Cascading Style Sheets Dave Edsall IAGenWeb County Coordinator’s Conference June 30, 2007.
CO1552 – Web Application Development Cascading Style Sheets.
CSS CSS is short for C ascading S tyle S heets. It is a new web page layout method that has been added to HTML to give web developers more control over.
Session 1 SESSION 1 Working with Dreamweaver 8.0.
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.
Creating a Form on a Web Page
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Week 9 - Form Basics Key Concepts 1. 1.Describe common uses of forms on web pages 2.Create forms on web pages using the form, input, textarea, and select.
1 Dr Alexiei Dingli Web Science Stream A ROR Blog.
1 Dr Alexiei Dingli Web Science Stream A ROR Twitter.
audio video object Options: controls autoplay Need to define height and width Options: controls autoplay.
1 More About HTML Tables and Images. 22 Objectives You will be able to Create tables in HTML. Include images in your HTML page. Create links to other.
1 Dr Alexiei Dingli Web Science Stream Web We’ll implement a voting mechanism Using AJAX Web 2.0.
Web Foundations TUESDAY, NOVEMBER 19, 2013 LECTURE 31: DREAMWEAVER: MODIFY MENU AND PROPERTY PANEL.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 26 - Case Study: Active Server Pages and XML Outline 26.1 Introduction 26.2 Setup and Message.
Week 8 – Part 2 Page Layout Basics Key Concepts 1.
Cascading Style Sheets Level 2. Course Objectives, Session 1 Level 1 Quick Review Chapter 8: Adding Graphics to Web Pages Chapter 9: Sprucing Up Your.
>> PHP: Insert Query & Form Processing. Insert Query Step 1: Define Form Variables Step 2: Make DB Connection Step 3: Error Handling Step 4: Define the.
CSS Cascading Style Sheets. Cascading Style Sheet (CSS) A cascading style sheet (CSS) is a set of rules that define styles to be applied to entire Web.
Create, Update and Delete Carol Wolf Computer Science.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
Microsoft Expression Web-Illustrated Unit F: Enhancing a Design with CSS.
CIT 256 CSS Intro & Dreamweaver Built-in Layouts Dr. Beryl Hoffman.
Rails and routing INFO 2310: Topics in Web Design and Programming.
28 Copyright © 2009, Oracle. All rights reserved. Customizing the Oracle Business Intelligence User Interface.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
Creating and Editing a Web Page Using Inline Styles
HTML. HTML: What is it? – HTML stands for Hyper Text Markup Language – An HTML file is a text file containing small markup tags – The markup tags tell.
Building a Website: Layout Fall Overall Structure: Home Page Title Section Title Frame Picture UNCP Math Menu Content Footer Contact Information.
CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.
Creating Web Pages with Links, Images, and Embedded Style Sheets
 Add one element at a time  If it doesn’t do what you want, › Delete it › DON’T just keep piling on more items.
INTERNET APPLICATIONS CPIT405 Forms, Internal links, meta tags, search engine friendly websites.
Cascading Styles Sheets Positioning HTML elements.
CSS Introductions. Objectives To take control of the appearance of a Web site by creating style sheets. To use a style sheet to give all the pages of.
Using the HTML and CSS Validation Services
XHTML Basics.
XHTML Basics.
XHTML Basics.
Intro to Web Development Links
XHTML Basics.
XHTML Basics.
Presentation transcript:

1 Dr Alexiei Dingli Web Science Stream Helpers, Forms and Layouts

2 Controller should hold all of our application logic Views should only contain the persentational code Helpers –chunks of code which can be reused throughout an application –every helper is available to every view Helpers

3 App/views/stories/new.html.erb name: link: Let’s work on some Forms

4 Using form_for –Form tags will be generated for us –We gain access to instance methods –Appropriate viables will be set for us –Appropriate URIs will be called –Different HTML objects can be used such as text_field, password_fiend, check_box, text_area Explanation

5 Start a server –ruby script/server Goto – Error? Let’s see what we have so far...

6 App/controllers/stories_controller.rb Creating a NEW empty record def = Story.new end Let’s add to the controller

7 Start a server –ruby script/server Goto – Path Error? Let’s see what we have so far...

8 Ideally every model should become a resource But how do we find resources? By using routing configurations –Config/routes.rb Resources

9 ActionController::Routing::Routes.draw do |map| map.resources :stories map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' end Routes.rb

10 URLAction GET /storiesIndex GET /stories/newNew POST /storiesCreate GET /stories/1Show GET /stories/1/editEdit POST /stories/1Update DELETE /stories/1Destroy What’s the effect of that line?

11 URLAction GET /storiesIndex GET /stories/newNew POST /storiesCreate GET /stories/1Show GET /stories/1/editEdit POST /stories/1Update DELETE /stories/1Destroy Actions on single stories and those on all!

12 Start a server –ruby script/server Goto – Let’s see what we have so far...

13 Right click on the browser page View the source code What about the HTML?

14 Two text field and a submit button A form element Action submission The authenticity_token to counter Cross- Site-Request-Forgery attacks What happens if we try to save? Spot the HTML

15 App/controllers/stories_controller.rb def = end Where will it send the control after the function? Saving to Database

16 But we don’t have one! And we don’t need one! App/controllers/stories_controller.rb def = redirect_to ‘ end Create.html.erb

17 stories_path/stories new_story_path/stories/new Some helpers

18 def = redirect_to stories_path end How to make even better code!

19 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" xml:lang="en" lang="en"> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> Shovell Shovell Creating a layout for the whole application... App/views/layout/application.html.erb

20 App/views/layout/application.html.erb Underneath the title tag, add... – Underneath the h1 tag, aff – How to make nicer views?

21 Inform HTML that a CSS exists called /stylesheets/style.css A pointer to where our views should be displayed 2 magic lines...

22 body { background-color: #666; margin: 15px 25px; font-family: Helvetica, Arial, sans-serif; } #content { background-color: #fff; border: 10px solid #ccc; padding: 10px 10px 20px 10px; } Let’s add the CSS... /stylesheets/style.css

23 Start a server –ruby script/server Goto – Let’s see what we have so far...

24 Not Adobe’s Flash But ROR’s Flash –Rails temporary data store –Allows us to send small messages to the browser –Good for status information Flash...

25 Just add the command flash[:notice] = ‘Story submission succeeded’ We can have different flashes such as :notice, :warning and :error Just add the command to stories_controller.rb just before the redirect command How shall we Flash?

26 Application.html.erb just before Where shall we display the Flash?

27 Add some layout to the style.css #notification { border: 5px solid #9c9; background-color: #cfc; padding: 5px; margin: 10px 0; } Making Flash pretty

28 App/models/story.rb There are various validations validates_presence_of :name, :link Adding validations...

29 Stories_controller.rb def = Story.new(params[:story]) flash[:notice] = 'Story submission succeeded' redirect_to stories_path else render :action => 'new‘ #renders the html only end Better redirection

30 Start a server –ruby script/server Goto – Let’s see what we have so far...

31 Have a look at the HTML code in the browser... Do you see a div with value “fieldsWithErrors” ? –Generated automatically by form_for helper –Why not format it? Better error handling!

32.fieldWithErrors { border: 5px solid #f66; } Add more css

33 At the top of New.html.erb Add the error message

34 A useful error message will indicate blank fields Some textual hints are shown A red border will highlight the field Result

35 Start a server –ruby script/server Goto – Let’s see what we have so far...

36 Questions?