1 Dr Alexiei Dingli Web Science Stream Web 2.0. 2 We’ll implement a voting mechanism Using AJAX Web 2.0.

Slides:



Advertisements
Similar presentations
1/7 ITApplications XML Module Session 8: Introduction to Programming with XML.
Advertisements

CIS 4004: Web Based Information Technology Spring 2013
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.
Web Pages and Style Sheets Bert Wachsmuth. HTML versus XHTML XHTML is a stricter version of HTML: HTML + stricter rules = XHTML. XHTML Rule violations:
Trestle Generator Industrial-strength scaffolding for Ruby on Rails web application development.
JavaScript and Ajax INFO 2310: Topics in Web Design and Programming.
Davis Dai. Introduction  Acronym for “asynchronous JavaScript and XML”  Combination of various technologies  Was not developed as an official standard.
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
INFORMATION ORGANIZATION LAB SEPTEMBER 15, 2009 LAST WEEK ON IO LAB Write your first Greasemonkey script. Complete the CSS self-test. You can find links.
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Ajax Dr Jim Briggs WEBP Ajax1. 2 Ajax Asynchronous JavaScript And XML Method of creating more interactive web applications Moves more of the application.
Creating a wiki blog. Run apps that come with instant rails distribution select I /rails applications/open ruby console window Cd to cookbook or typo.
-Uday Dhokale.  What is it ??? Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.  Features a unique, easy-to-use.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
© 2006 by IBM 1 How to use Eclipse to Build Rich Internet Applications With PHP and AJAX Phil Berkland IBM Software Group Emerging.
Prof. James A. Landay University of Washington Spring 2008 Web Interface Design, Prototyping, and Implementation Rich Internet Applications: AJAX, Server.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
JQuery CS 268. What is jQuery? From their web site:
Ruby on Rails CSCI 6314 David Gaspar Jennifer Garcia Avila.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
INTRODUCTION TO DHTML. TOPICS TO BE DISCUSSED……….  Introduction Introduction  UsesUses  ComponentsComponents  Difference between HTML and DHTMLDifference.
1 Dr Alexiei Dingli Web Science Stream Models, Views and Controllers.
Simple Script.ac.ulous Mike Patterson The University of Aberdeen.
CS 4720 RESTfulness and AJAX CS 4720 – Web & Mobile Systems.
Ruth Betcher Ruth Christie
Yahoo! User Interface (YUI) Library Natly Mekdara.
 2008 Pearson Education, Inc. All rights reserved Ajax-Enabled Rich Internet Applications.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
1 Dr Alexiei Dingli Web Science Stream Helpers, Forms and Layouts.
Title, meta, link, script.  The title looks like:  The tag defines the title of the document in the browser toolbar.  It also: ◦ Provides a title for.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
Instructor, Dr. Khalili Bahram Jeevan Kumar Gogineni.
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
The Document Object Model. The Web B.D, A.D. They aren’t web pages, they’re document objects A web browser interprets structured information. A server.
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.
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.
© Copyright IBM Corporation 2007 AP/Americas April 15-18, 2007 Anaheim, California Introduction to RubyOnRails - a J2EE replacement? Russell Scheerer –
Associations INFO 2310: Topics in Web Design and Programming.
1 Dr Alexiei Dingli Web Science Stream A ROR Blog.
Chapter 15 © 2009 by Addison Wesley Longman, Inc Overview of Rails - Rails is a development framework for Web-based applications - Rails is written.
Photo Gallery INFO 2310: Topics in Web Design and Programming.
Session I Chapter 1 - Introduction to Web Development
CS 142 Lecture Notes: Rails ActiveRecordSlide 1 Model for Student Table SELECT * FROM students; | id | name.
Building Rich Web Applications with Ajax Linda Dailey Paulson IEEE – Computer, October 05 (Vol.38, No.10) Presented by Jingming Zhang.
1 Dr Alexiei Dingli Web Science Stream A ROR Twitter.
Developing AJAX Web applications with Castle Monorail David De Florinier Gojko Adzic Skills Matter 12/06/08.
Ajax. –Asynchronous JavaScript and XML –Umbrella term for technologies that often: Use client-side scripting for layout and formatting Use less than full.
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.
Lecture 13b Rails – Controllers and Views Topics SaaSSaaS Readings: SaaS book Ch March 3, 2014 CSCE 740 Software Engineering.
1 Dr Alexiei Dingli Web Science Stream Installing ROR.
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.
Rails and routing INFO 2310: Topics in Web Design and Programming.
Positioning Objects with CSS and Tables
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
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.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
JavaScript & Introduction to AJAX
1 Objects In JavaScript. 2 Types of Object in JavaScript Built-in objects User Defined Objects Browser Object Document Object Model.
1 Scriptaculous. 2 Thomas Fuchs built it on prototype Takes you from where Prototype left you –Prototype provides ability to Make.
Melbourne LUG Presentation Learning Rails and Ruby - making webapps easier.
Prototype.
Human Computer Interaction
AJAX and REST.
AJAX.
HTML5 Level I Session I Chapter 1 - Introduction to Web Development
Chapter 15 Introduction to Rails.
DR. JOHN ABRAHAM PROFESSOR UTPA
Presentation transcript:

1 Dr Alexiei Dingli Web Science Stream Web 2.0

2 We’ll implement a voting mechanism Using AJAX Web 2.0

3 ruby script/generate model Vote story_id:integer Creating the vote model

4 class CreateVotes < ActiveRecord::Migration def self.up create_table :votes do |t| t.integer :story_id t.timestamps end def self.down drop_table :votes end The vote migration

5 rake db:migrate Apply the migration

6 In the case of votes –A story might have many votes –Has_many is the relationship to use App/models/story.rb –has_many :votes More on relationships

7 ruby script/console s = Story.find(:first) s.votes s.votes.create s.votes.size Let’s test it...

8 App/models/vote.rb Add –belongs_to :story Use the reload! command in the console –Try v = Vote.find(:first) v.story Finalising the relationship

9 Stories_controller.rb def = Story.find(:first, :order => 'RANDOM()') end def = Story.new end def = Story.find(params[:id]) end Showing our stories

10 App/views/stories/show.html.erb Displaying the stories!

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

12 Change the index.html to A random link: Better randomization

13 Generate –ruby script/generate controller Votes create Arrange the routes –Routes.rb map.resources :stories, :has_many => :votes Create the routes –rake routes Let’s create the votes

14 Nested routes of the form... /stories/:story_id/votes /stories/1/votes Looking at the rake routes

15 Asynchronous JavaScript and XML –Make web browser communicate with a server without reloading the page –Also called remote scripting –More dynamic and responsive experience just like in a desktop application –Uses XMLHttpRequest, XHTML, CSS and DOM –Supported by most browsers –Used in Web 2.0 applications (Digg, Flickr, etc) Ajax

16 Rails –ships with Ajax support –encourages its use –is bundled with the Prototype JavaScript library –And also script.aculo.us which takes care of visual elements Rails + Ajax

17 Core Effects: Effect.Highlight, Effect.Morph, Effect.Move, Effect.Opacity, Effect.Scale, Effect.Parallel, Effect Queues Combination Effects: Effect.Appear, Effect.BlindDown, Effect.BlindUp, Effect.DropOut, Effect.Fade, Effect.Fold,Effect.Grow, Effect.Puff, Effect.Pulsate, Effect.Shake, Effect.Shrink, Effect.SlideDown, Effect.SlideUp, Effect.Squish, Effect.SwitchOff, Effect.ScrollTo Effect helpers: Effect.Transitions, Effect.Methods, Effect.tagifyText, Effect.multiple, Effect.toggle Behaviours: Draggable, Droppables, Sortable, Form.Element.DelayedObserver Controls: Ajax.InPlaceEditor, Ajax.InPlaceCollectionEditor, Ajax.Autocompleter, Autocompleter.Local, Slider Miscellaneous: Builder, Sound, Unit Testing Some features of script.aculo.us

18 Just underneath the tag of application.html.erb add – This will automatically include –Prototype.js –Effects.js –Dragdrop.js –Controls.js –Application.js Adding the JavaScript libraries

19 Score: do %> Modifying the stories/show.html.erb

20 #vote_score { float: right; color: #9c9; } #vote_form { margin: 10px 0; } #vote_form input { padding: 3px 5px; border: 3px solid #393; background-color: #cfc; text-decoration: none; color: #393; } #vote_form input:hover { background-color: #aea; } Adding some styles

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

22 class VotesController < ApplicationController def = end end Adding votes

23 Used to modify parts of an existing page Send JavaScript commands Make a view called create.rjs and add the following: –page.replace_html 'vote_score', "Score: –page[:vote_score].visual_effect :highlight RJS Templates

24

25 class VotesController < ApplicationController def = respond_to do |format| format.html { } format.js end end What if the browser does not supports Ajax?

26 Deal with parts of the page constantly reused Eg a voting history What’s a partial?

27 Score: No votes yet! 'votes/vote', :collection %> do %> Let’s add a voting history! stories./show.html.erb

28 No votes yet! 'votes/vote', :collection %> Let’s add a voting history! stories./show.html.erb

29 Views/votes/_vote.html.erb Notes: short => "%d %b %H:%M" Create a partial

30 Create.js page.replace_html 'vote_score', "Score: page[:vote_score].visual_effect :highlight page[:vote_history].replace_html :partial => 'vote', :collection Updating the history during a vote

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

32 Questions?