Ruby on Rails 101.2. WTF? Created by Matz in 1993 Inspired by Smalltalk Rubygems = CSPAN Rake = ant Rdoc = javadoc.

Slides:



Advertisements
Similar presentations
More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
Advertisements

Chapter 2.2 – More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld senior.
Ruby (on Rails) CSE 190M, Spring 2009 Week 2. Arrays Similar to PHP, Ruby arrays… – Are indexed by zero-based integer values – Store an assortment of.
Ruby Reuben Mallaby.
Creating Web Services with Ruby on Rails Robert Thew Internet and Web Systems II.
Language of the Month If it’s December, it must be Ruby! Adam Coffman and Brent Beer.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
PHP (2) – Functions, Arrays, Databases, and sessions.
Ruby on Rails. What's Ruby  A programming language  Developed by Yukihiro Matsumoto (aka Matz) in the 1990s  A programming language  Developed by.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Introduction to Ruby CSE 413 Autumn 2008 Credit: Dan Grossman, CSE341.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
Ruby (on Rails) CSE 190M, Spring 2009 Week 1. The Players Kelly "Everyday I'm Hustlin' " Dunn Kim "Mouse" Todd Ryan "Papa T" Tucker.
The Ruby Programming Language
UC Berkeley Hello Rails. Review: MVC Goal: separate organization of data (model) from UI & presentation (view) by introducing controller –mediates user.
1 JavaScript. 2 What’s wrong with JavaScript? A very powerful language, yet –Often hated –Browser inconsistencies –Misunderstood –Developers find it painful.
Ruby! Useful as a scripting language – script: A small program meant for one time use – Targeted towards small to medium size projects Use by: – Amazon,
1 Dr Alexiei Dingli Web Science Stream Advanced ROR.
Ruby! Ronald L. Ramos. What is Ruby? Ruby is a scripting language designed by Yukihiro Matsumoto, also known as Matz. It runs on a variety of platforms,
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
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.
1 Names, Scopes and Bindings Aaron Bloomfield CS 415 Fall
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Ruby on Rails. What is Ruby? Programming Language Object-oriented Interpreted.
Introduction to Ruby WING Group Meeting 9 Jun 2006 Min-Yen Kan WING Group Meeting 9 Jun 2006 Min-Yen Kan.
Associations INFO 2310: Topics in Web Design and Programming.
Photo Gallery INFO 2310: Topics in Web Design and Programming.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Recap form last time How to do for loops map, filter, reduce Next up: dictionaries.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Programming in Java CSCI-2220 Object Oriented Programming.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Web Development 101 Presented by John Valance
+ Ruby and other programming Languages Ronald L. Ramos.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Java Basics Opening Discussion zWhat did we talk about last class? zWhat are the basic constructs in the programming languages you are familiar.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Introduction to Ruby&Rails Yuri Veremeyenko Monica Verma.
Python Let’s get started!.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Scope, Aliasing, Tuples & Mutability Intro2CS – week 4a 1.
1 Getting Started with Ruby. 2 What’s Ruby? Ruby is an OO, dynamic, agile language –Everything’s an object For example, try puts -1.abs –Derives strengths.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
CSE 130 : Winter 2009 Programming Languages Lecture 11: What’s in a Name ?
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
OOP Basics Classes & Methods (c) IDMS/SQL News
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.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Today Review passing by reference and pointers. null pointers. What is an Object? Winter 2016CMPE212 - Prof. McLeod1.
Ruby Tien Ho and Brandon Hostetter. Overview ▸ Object-oriented, functional, imperative, and reflective ▸ Interpreted language ▸ Influenced by Perl, Smalltalk,
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
JRuby on Rails Presenter Name
JRuby on Rails Brian Leonard ブライアン レオナルド
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
Scope History of Ruby. Where can you use Ruby? General Features.
Introduction to Python
Java Primer 1: Types, Classes and Operators
Ruby Tooling in NetBeans
Programming Language Concepts (CIS 635)
Building Web Applications
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Ruby Testing 2, 11/9/2004.
Tonga Institute of Higher Education
Python Primer 1: Types and Operators
JavaScript CS 4640 Programming Languages for Web Applications
Code Blocks, Closures, and Continuations
JavaScript CS 4640 Programming Languages for Web Applications
Presentation transcript:

Ruby on Rails 101.2

WTF? Created by Matz in 1993 Inspired by Smalltalk Rubygems = CSPAN Rake = ant Rdoc = javadoc

How its like Java Object orientated Supports single inheritance Has exceptions Runs on multiple OS’s Runs on Java runtime (using jruby)

How it differs Loosely typed until assigned Supports closures / passing blocks Supports ‘modular’ design (mixins) Poor language level support for mulit- threaded execution No primitives (int, float etc)

When might you use it?

YARJC: Yet another Rails vs. Java Comparison Justin Gehtland recently tried re- implementing one of his web applications in Ruby on Rails instead of his normal Java Spring/Hibernate setup, according to a Slashdot post.

YARJC: Yet another Rails vs. Java Comparison Justin Gehtland recently tried re- implementing one of his web applications in Ruby on Rails instead of his normal Java Spring/Hibernate setup, according to a Slashdot post. Convention over configuration

Setup –The version that comes with Leopard isn't high enough. You'll need to get he source and make / sudo make install. Then run 'gem install sqlite3- ruby' (all on the mac). The binaries should do for windows. al/ html

Resources land/web/rails-resourceshttp://groups.google.com/group/ruby_ire land/web/rails-resources ;)

What we’ll cover :symbols Passing blocks Creating objects Closures

:symbols

“a”.intern = :a Symbols are ‘weird string’s Immutable (cannot be reassigned) Used internally to represent language elements eg: 100 would have a symbol assocaited with it Commonly used in hash maps as keys

Passing blocks (goal posts)

3.times do puts “Hello world” End myArray = Array.new [3, 4, 3, 9] myArray.each do |i| puts I end Sans goalpoasts Avec goalpoasts

3.times { puts “Hello world” } myArray = Array.new [3, 4, 3, 9] myArray.each { |i| puts i } Sans goalpoasts Avec goalpoasts

Hashes myHash = { :name => “James”, :occupation => “Programmer” } myHash.each { |i, k| puts “#{i}:#{k}” }

Everything is an object

class James initialize puts = 3 # defines a member variable end # provides an accessor def end # set x from outisde of the def x= = arg end

class Person attr_accessor :second_name initialize puts = 3 # defines member variable end

~ jkennedy$ irb irb(main):001:0> require 'test' => true irb(main):002:0> j = James.new initialising => # irb(main):003:0> j.x => 3 irb(main):004:0> j.x= 5 => 5 irb(main):005:0> j.x => 5 irb(main):006:0>

Exceptions

class RaisingExceptionionator def initialize begin file = open “some_file” rescue file = STDIN retry # error? end

Closures

# Example 1: def thrice yield end x = 5 puts "value of x before: #{x}" thrice { x += 1 } puts "value of x after: #{x}"

# Example 2: local scope def thrice_with_local_x x = 100 yield puts "value of x at end of thrice_with_local_x: #{x}" end x = 5 thrice_with_local_x { x += 1 } puts "value of outer x after: #{x}"

# Example 3: thrice do # note that {...} and do...end are equivalent y = 10 puts "Is y defined inside the block where it is first set?" puts "Yes." if defined? y end puts "Is y defined in the outer context after being set in the block?" puts "No!" unless defined? y

#Example 4: yield and scope def six_times(&block) thrice(&block) end x = 4 six_times { x += 10 } puts "value of x after: #{x}"

# Example 5 # So do we have closures? Not quite! We can't hold on #to a &block and call it later at an arbitrary # time; it doesn't work. This, for example, will not #compile: # # def save_block_for_later(&block) # saved = █ # end # # But we *can* pass it around if we use drop the &, and use block.call(...) instead of yield: def = b # Note: no ampersand! This turns a block into a closure of sorts. end

# Example 5 : … continued save_for_later { puts "Hello!" } puts "Deferred execution of a

@saved_proc_new = Proc.new { puts "I'm declared with Proc.new." = proc { puts "I'm declared with proc." = lambda { puts "I'm declared with lambda." } def some_method puts "I'm declared as a method." = method(:some_method) puts "Here are four superficially identical forms of

Modules Modules cannot be instantiated Define a set of ‘behaviours’ which an object can ‘inherit’ Module Politeness def say_hello puts “Hello” end

class Ambassador def initialize require ‘Politeness’ end kofi = Ambassador.new kofi.say_hello

Rails : rails myfirstproject : cd myfirstproject : rake rails:freeze:gems : script/generate - -help : script/destroy - -help : script/migration - -help : script/resource - -help : script/scaffold - -help

Rails : rails myfirstproject : cd myfirstproject : rake rails:freeze:gems : script/generate - -help : script/destroy - -help : script/migration - -help : script/resource - -help : script/scaffold - -help Freezing rails Imports the rails Code into your app

Sqllite :script/generate model Person name:string phone:integer biography:text :rake db:create :rake db:migrate :sqllite3 db/development.sqllite3 sqllite>.tables

Anatomy of a project Global configuration Methods available in views Active Record Classes * Templates Active Record Classes * URL => controller configuration

CRUD Create => [ new, update] Read => [ list, show] Update => [edit, update] Delete => [destroy]

Create rake rails:freeze:gems def = Item.new end def = Item.new params[:item] flash[:notice] = ‘Item was created’ else render :action => “new” end

Read rake rails:freeze:gems def = Item.find :all end def = Item.find params[:id] end

Update rake rails:freeze:gems def = Item.find params[:id] end def = Item.find params[:id] end

Delete rake rails:freeze:gems def = Item.find end

Adding Authentication./script/plugin install weenie.net/projects/plugins/restful_authenti cation/./script/generate authenticated user sessions Active Record Session only

Setting site template #{APP_ROOT}/app/views/layout/#{mod el_name}.erb renders content

Get a template Google: ‘yui builder’