Introduction to RoR Ruby on Rails

Slides:



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

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
Java Script Session1 INTRODUCTION.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
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.
Chapter 15 © 2010 by Addison Wesley Longman, Inc Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in Use spread rapidly.
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
Introduction to Model-View-Controller (MVC) Web Programming with TurboGears Leif Oppermann,
Multiple Tiers in Action
Guide To UNIX Using Linux Third Edition
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
UNIT-V The MVC architecture and Struts Framework.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
1 Introduction to Web Development. Web Basics The Web consists of computers on the Internet connected to each other in a specific way Used in all levels.
Ruby on Rails. What is Ruby on Rails? Ruby on Rails is an open source full-stack web framework. It is an alternative to PHP/MySQL. It can render templates,
Ruby on Rails CSCI 6314 David Gaspar Jennifer Garcia Avila.
UC Berkeley Hello Rails. Review: MVC Goal: separate organization of data (model) from UI & presentation (view) by introducing controller –mediates user.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
1 An Introduction to the Development of Web Applications using Ruby on Rails with Ajax Ansgar Berhorn, B.Sc. and Mike Rowe, Ph.D.
Lecture 19 Web Application Frameworks Boriana Koleva Room: C54
1 Dr Alexiei Dingli Web Science Stream Introducing Rails.
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 Dynamic Web Pages Using PHP and MySQL CS 320.
Lecture 11 Rails Topics SaaSSaaS Readings: SaaS book Ch February CSCE 740 Software Engineering.
Chapter 15 © 2009 by Addison Wesley Longman, Inc Overview of Rails - Rails is a development framework for Web-based applications - Rails is written.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
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.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Introduction to Ruby&Rails Yuri Veremeyenko Monica Verma.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
Web Database Programming Using PHP
Java Server Pages Can web pages be created specially for each user?
Intro to HTML CS 1150 Spring 2017.
Introduction to RoR Ruby on Rails
Intro to HTML CS 1150 Fall 2016.
MVC Architecture, Symfony Framework for PHP Web Apps
ASP MVP Web applications and Razor
1993 version of Mosaic browser.
Loops BIS1523 – Lecture 10.
Arrays: Checkboxes and Textareas
Web Database Programming Using PHP
Play Framework: Introduction
Ruby Tooling in NetBeans
PHP Introduction.
CS5220 Advanced Topics in Web Programming Course Overview
Intro to PHP & Variables
MVC Framework, in general.
Bruce Scharlau, University of Aberdeen, 2017
Chapter 14 Introduction to Ruby.
VISUAL BASIC.
Use of Mathematics using Technology (Maltlab)
T. Jumana Abu Shmais – AOU - Riyadh
Chapter 15 Introduction to Rails.
Web DB Programming: PHP
More ISP At a Glance.
8 6 MySQL Special Topics A Guide to MySQL.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Developing a Model-View-Controller Component for Joomla
JavaScript CS 4640 Programming Languages for Web Applications
An Introduction to JavaScript
CS5220 Advanced Topics in Web Programming Course Overview
Web Application Development Using PHP
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Introduction to RoR Ruby on Rails Yingcai Xiao

Ruby Interpreted ruby file.rb irb Object-oriented: Dynamic data typing encapsulation Inheritance (code reuse by sub-classing) polymorphism Dynamic data typing .

Data Structures & Algorithms Data Types: Scalars and Arrays Scalars: Numeric: Fixnum, Bignum, Float String (value type, p5 of C15.ppt) Arrays: non-uniform Array: similar to C++, with sub-array operations and shift, unshift, push, pop Associative Array, Hash, key=>value, Similar to PHP. .

Data Structures & Algorithms Operators/Controls no ++ or – gets/puts EOF for keyboard input: Ctrl-D (Unix/Mac), Crel-Z (PC) Case statement can be a right operand “for” loop is replaced by for-in for value in list puts value end .

Data Structures & Algorithms Operators/Controls break/next 3 object comparisons: == (value) equal (reference) eql (type) .

Data Structures & Algorithms UDT: class class Name .. end Class Name begins with upper case Instance name begins with lower case Constructor “new” calls initialize Classes are dynamic, can add members later. getter/setter .

Data Structures & Algorithms UDT: class, Inheritance class Name < Parent .. end Support multiple inheritance .

Data Structures & Algorithms UDT: Blocks & Iterators A segment of code delimited by { } or do/end Built-in iterators times: 5.times {puts “ISP”} each: list.each {|value| puts value} upto, step, collect .

Data Structures & Algorithms Pattern Matching string =~ /pattern/ Substitutions str.sub(pattern, replacement) str.gsub(pattern, replacement) word_table.rb .

Data Structures & Algorithms # word_table.rb from PWWW # Input: Text from the keyboard. All words in the input are # separated by white space or punctuation, possibly followed # by white space, where the punctuation can be a comma, a # semicolon, a question mark, an exclamation point, a period, # or a colon. # Output: A list of all unique words in the input, in alphabetical # order, along with their frequencies of occurrence .

Data Structures & Algorithms # word_table.rb freq = Hash.new line_words = Array.new # Main loop to get and process lines of input text while line = gets # Split the line into words line_words = line.chomp.split( /[ \.,;:!\?]\s*/) .

Data Structures & Algorithms # word_table.rb # Loop to count the words (either increment or initialize to 1) for word in line_words if freq.has_key?(word) then freq[word] = freq[word] + 1 else freq[word] = 1 end End .

Data Structures & Algorithms # word_table.rb # Display the words and their frequencies puts "\n Word \t\t Frequency \n\n" for word in freq.keys.sort puts " #{word} \t\t #{freq[word]}" end .

Ruby References https://www.ruby-lang.org https://www.ruby-lang.org/en/downloads/ https://www.ruby-lang.org/en/documentation/ https://www.tutorialspoint.com/ruby/ https://www.codecademy.com/learn/ruby http://tryruby.org/ .

Ruby Installation The current stable version is 2.3.3 (Dec. 2016) https://www.ruby-lang.org/en/downloads/ Needs down load tools: PC: RubyInstaller Mac/Unix: rbenv and RVM Need 2.2.0 above to run Active Support .

. Rails

Rails Framework for developing Web applications. A framework is a standardized system of reusable templates. Based on the MVC (Model-View-Controller) web application architecture. RoR (Ruby on Rails) uses predefined M,V,C classes (in Ruby) to form the templates. .

Architecture of a Four-Tier Application DBMS / Database Server Application Server WEB S E R V C L I N T Database User Interface Database Engine Supporting Software Database API Application Logic App User Interface Wednesday 3/18/2015 day and evening Architecture of a Four-Tier Application

Architecture of RoR Web Applications DBMS / Database Server RoR Web Applications WEBrick or any Web Server on the same system. Web C L I E N T Database User Interface Database Engine Supporting Software Database API (Model:ORM) Application Logic (Controller) App User Interface (View) Wednesday 3/18/2015 day and evening Architecture of RoR Web Applications

Rails MVC Architecture (PWWW) .

. Installing Rails

Rails Installation Rails comes with Ruby along with RubyGems PWWW uses SQLite3 (SQLite.org) for database Command line installations gem install sqlite3 gem install rails Or sudo gem install sqlite3 sudo gem install rails .

Rails Server Startup Start the webrick server (came with Rails) rails server webrick URL to access the server http://localhost:3000/ .

Rails Hosting http://www.railshosting.org/free-rails-hosting https://www.airpair.com/ruby-on-rails/posts/rails-host-comparison-aws-digitalocean-heroku-engineyard https://www.heroku.com/ http://api.rubyonrails.org/ Detailed instructions on using Amazon AWS Cloud: http://dsaigoud.com/amazon-aws-instance-setup-and-j2ee-app-deployment.jsp .

. Programming RoR Day

RoR Web Application Development Automatically generates web apps Apps are composed of MVC classes Similar to our PA3 but without GUI, everything is Command Line .

RoR Web Application Development A “Hello World” Example .

Architecture of RoR Web Applications DBMS / Database Server RoR Web Applications WEBrick or any Web Server on the same system. Web C L I E N T Database User Interface Database Engine Supporting Software Database API (Model:ORM) Application Logic (Controller) App User Interface (View) Wednesday 3/18/2015 day and evening Architecture of RoR Web Applications

Programming RoR: Examples >rails new greet .

Greet Example >rails generate controller say hello It generates the code for the controller class named “say” with a method named “hello”. say_controller.rb class SayController < ApplicationController def hello end .

Greet Example The same command also generated the code for the view app/views/say/hello.html.erb Embedded Ruby <!DOCTYPE html> <!-- hello.html.erb - the template for the greet application --> <html lang = "en"> <head> <title> greet </title> <meta charset = "utf-8" /> </head> <body> <h1> Hello from Rails </h1> </body> </html .

Programming RoR: Examples >rails new greet .

Dynamic response of the application server to a user request http://localhost:3000/say/hello 0. Web Client->HTTP Get->Webrick->Rails->App 1. Instantiate SayController class 2. Call the hello action method 3. Search the views/say directory for hello.html.erb 4. Process hello.html.erb with Erb 5. Return the resulting hello.html to the requesting browser

Greet Example Customization <!DOCTYPE html> <!-- hello.html.erb - the template for the greet application --> <html lang = "en"> <head> <title> greet </title> <meta charset = "utf-8" /> </head> <body> <h1> Hello from Rails </h1> It is now <%= t = Time.now %> <br /> Number of seconds since midnight: <%= t.hour * 3600 + t.min * 60 + t.sec %> </body> </html .

RoR Web Application Development A 4-tier Enterprise Example .

Architecture of RoR Web Applications DBMS / Database Server RoR Web Applications WEBrick or any Web Server on the same system. Web C L I E N T Database User Interface Database Engine Supporting Software Database API (Model:ORM) Application Logic (Controller) App User Interface (View) Wednesday 3/18/2015 day and evening Architecture of RoR Web Applications

ORM (Object Relation Model) We need to create a database for the enterprise application. The database is going to be relational. But we don’t have to define the schema using DDL. We will let Rails to do that for us. Rails will create a class to specify the schema: The name of the class (object model) is the singular of the relational table name. The name of the member variables are the names of the columns of the table. The member methods of the class are inherited from the ActiveRecord class. .

ORM (Object Relation Model) Here are the implementation steps: Create the application >rails new cars (2) Create the class to define the schema (cars/db/migrate) >rails generate scaffold corvette body_style:string miles:float year:integer (3) Create the database table >rake db:migrate (4) The application, the controller, the view, are all automatically created without writing a single line of Ruby code! (Familiar? PA3) http://localhost:3000/corvettes .

Programming RoR: Examples http://localhost:3000/corvettes .

Programming RoR: Examples When clicking on “New corvette” .

Programming RoR: Examples After entering a “New corvette” .

Programming RoR: Examples UI for Editing .

Programming RoR: Examples For Destroy .

Application? Recreate your Social List web application using RoR in 5 minutes without writing a single line of code! .

Agile Design

localhost:3000/corvettes/new

Schema.rb

Adding new column ‘color’ to our corvette rails generate migration AddColorToCorvette color:string

Migration File

rake db:migrate

Schema.rb after migration

Add a textbox to our form

localhost:3000/corvettes/new

Techniques for the above What did we learn? Knowledge Comprehension Application Creation Techniques for the above .