Ruby on Rails TKK, Otto Hilska

Similar documents
CS 5142 Scripting Languages

Ruby on Rails. SITC Workshop Series American University of Nigeria FALL 2017

Contents in Detail. Foreword by Xavier Noria

Lecture 4. Ruby on Rails 1 / 49

Lecture 4. Ruby on Rails 1 / 52

Introduction and first application. Luigi De Russis. Rails 101

CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Dan Grossman Winter 2013

Introduction to Ruby on Rails

Introduction to Ruby on Rails

Ruby logistics. CSE341: Programming Languages Lecture 19 Introduction to Ruby and OOP. Ruby: Not our focus. Ruby: Our focus. A note on the homework

Are you using Ruby on Rails?

Ruby. Mooly Sagiv. Most slides taken from Dan Grossman

iflame INSTITUTE OF TECHNOLOGY

Ruby on Rails Welcome. Using the exercise files

Introduction to Ruby on Rails

Your First Ruby Script

Software Engineering 2 (SWT2) Chapter 2: Introduction into Ruby on Rails

CSCI-2320 Web Programming: Ruby on Rails

Courslets, a golf improvement web service. Peter Battaglia

CSE 341, Autumn 2015, Ruby Introduction Summary

INDEX. Symbols & Numbers

Strategies for Rapid Web Prototyping. Ruby on Rails. Clemens H. Cap

Why Rails and Design for an Applica5on

15.1 Origins and Uses of Ruby

Boldface numbers indicate illustrations, code listings, and tables.

Web Application Expectations

What is Ruby? CSc 372. Comparative Programming Languages. 27 : Ruby Introduction. Department of Computer Science University of Arizona

Overview of the Ruby Language. By Ron Haley

Introduction CMSC 330: Organization of Programming Languages. Books on Ruby. Applications of Scripting Languages

Ruby Topic Maps. Introduction to Ruby. Benjamin Bock.

INTRODUCTION TO RUBY PETER COOPER

Ruby Gem Internals by Examples

CHORDS: Cloud-Hosted Real-time Data

Ruby, with foxes. Ruby, cont d. Warning. why's (poignant) Guide to Ruby

Day 2: 19/April/2012 Installing Aptana IDE; Integrated Development Environment And Rails

CS169.1x Lecture 6: Basic Rails" Fall 2012"

Alleviate the Apprehension of Coding in Ruby

Adding Static Typing to Ruby

MRI Internals. Koichi Sasada.

JRuby and Ioke. On Google AppEngine. Ola Bini

Teaching Ruby on Rails Dr Bruce Scharlau Computing Science Department University of Aberdeen Aberdeen, AB24 3UE

A Closer Look at XPages in IBM Lotus Domino Designer 8.5 Ray Chan Advisory I/T Specialist Lotus, IBM Software Group

Rails: Views and Controllers

Lean & Mean Tokyo Cabinet Recipes. Ilya

Installation Download and installation instructions can be found at

Convention over Configuration

عناوین تاریخچه ویژگیها 6 جزءاصلی کاربردها 2 از 34

RESPONSIVE WEB DESIGN IN 24 HOURS, SAMS TEACH YOURSELF BY JENNIFER KYRNIN

Pete Forde Partner, Unspace Interactive Toronto, ON

Web System Development by Ruby on Rails. Day 3(4/Oct/2012) First Project Internationalization

Rails Engines. Use Case. The Implementation

Ruby. A Very Brief Introduction. Andreas Klappenecker

Web System Development by Ruby on Rails. Day 1(20/Sept/2012) Guidance Installation of Ruby, Gems, Rails, and Aptana

Ruby on Rails 3 March 14th, 2011 Ken Li Allison Pon Kyra Leimert Matt Delaney Edward Bassett

Lecture 1. Basic Ruby 1 / 61

Groovy & Grails Scripting for Modern Web Applications. Rohit Nayak Talentica Software

Agile Web Development With Rails (4th Edition - Rails 3 & Ruby 1.9) By Sam Ruby

DOWNLOAD : THE RUBY PROGRAMMING LANGUAGE

Basics of Web. First published on 3 July 2012 This is the 7 h Revised edition

Combining Static and Dynamic Typing in Ruby: Two Approaches. Jeff Foster University of Maryland, College Park

Casabac Unicode Support

RubyConf China. Why Ruby? Yukihiro "Matz" Matsumoto. Copyright (c) 2008 Yukihiro "Matz" Matsumoto, No rights reserved

Ruby: Introduction, Basics

DRYing Out MVC (ESaaS 5.1)"

Application Design and Development: October 30

Ruby AN OVERVIEW. Luigi De Russis Dipartimento di Automatica e Informatica Politecnico di Torino

Active Model Basics. December 29, 2014

All India Council For Research & Training

Validations vs. Filters

Recommendations for Web Development and Deployment Using Team Developer

WKA Studio for Beginners

JavaScript: the Big Picture

Rails: MVC in action

Enterprise Software Architecture & Design

What is Scripting? CSCI: 4500/6500 Programming Languages. Higher-level Programming. Origin of Scripting Languages. Contemporary Scripting Languages

Motivations. Luigi De Russis. Why Ruby (on Rails)?

COM401 Software Engineering Laboratory

BUILD YOUR OWN RUBY ON RAILS WEB APPLICATIONS BY PATRICK LENZ DOWNLOAD EBOOK : BUILD YOUR OWN RUBY ON RAILS WEB APPLICATIONS BY PATRICK LENZ PDF

Ruby: Introduction, Basics

Attacks Against Websites 3 The OWASP Top 10. Tom Chothia Computer Security, Lecture 14

web frameworks design comparison draft - please help me improve it focus on Model-View-Controller frameworks

At the Forge. What Is Ruby? Getting Started with Ruby. Reuven M. Lerner. Abstract

Progress report of "Ruby 3 Concurrency"

Web Presentation Patterns (controller) SWEN-343 From Fowler, Patterns of Enterprise Application Architecture

Keeping Rails on the Tracks

JRuby: What, Why, How...Do it Now!

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm

CSE 413 Programming Languages & Implementation. Hal Perkins Winter 2019 Ruby Containers, Blocks, and Procs

CS 390 Software Engineering Lecture 6 Ruby

comparing groovy & jruby *

Extending Ruby with C

Tuesday, January 13, Backend III: Node.js with Databases

why you should use Ruby

Ruby on Rails. Origin Drive Destination

welcome to BOILERCAMP HOW TO WEB DEV

Ruby on Rails 3. Robert Crida Stuart Corbishley. Clue Technologies

Varargs Training & Software Development Centre Private Limited, Module: HTML5, CSS3 & JavaScript

Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

Computer Science Seminar. Whats the next big thing? Ruby? Python? Neither?

Ruby: Introduction, Basics

Transcription:

Ruby on Rails intro @ TKK, 25.5.2009 Otto Hilska 1

Today s agenda 1. The Ruby programming language 2. Ruby on Rails framework 3. An example project 2

About me Started Nodeta Oy in 2004 10+ employees always recruiting focus on Ruby on Rails web development Ruby on Rails since 2005 Working on a global Rails project since 2007 3

Ruby is... dynamic interpreted object-oriented productive, enjoyable not very fast 4

Ruby s history Yukihiro Matz Matsumoto started the project around 1995 Most developers were Japanese... and so were the mailing lists. 5

Ruby today Huge hype around Ruby on Rails open-sourced in July 2004 Enterprises have adopted Ruby Several Ruby implementations 1.8.6 1.9.1 JRuby 6

Motivation Productive Fun Ruby on Rails 7

IDEs RubyMine Aptana RadRails Netbeans 8

Text editors 9

Some examples you can try these at http://www.ruby-lang.org/ 10

% irb >> a = 3 => 3 >> puts a + 2 5 => nil 11

>> 1337 ** 3 => 2389979753 12

>> 1337.class => Fixnum >> (1337 ** 3).class => Bignum 13

>> 3.times { puts "hello world" } hello world hello world hello world => 3 14

def fib(n) return 0 if n == 0 return 1 if n == 1 fib(n-1) + fib(n-2) end function declaration explicit return comparison reverse-if implicit return function call puts fib(15) 15

a = [ otto, veikko, mauno, juhani, veikko ] puts a.sort.uniq.join(, ) juhani, mauno, otto, veikko 16

Naming conventions Variables: age, total_length Constants: MAXIMUM_LENGTH Classes and modules: WebServer, ApplicationController Methods: age, age=, is_alive?, kill! 17

Other conventions 2 space indents File names: class ApplicationController lives in application_controller.rb 18

Common types Fixint and Bigint: 5, 1234567890 Float: 3.14 String: hello world Symbol: :utc Array: [1, 2, 3, text, 4.0], %w(array of strings) Hash: { :name => Otto, :email => mutru@mutru.fi }, my_hash[:name] = Otto Range: 1..10 19

20

Type conversions a = 3 + 2 => 5 b = a * 3 => aaa a + b TypeError: String can't be coerced into Fixnum a.to_s + b => 5aaa 21

Type conversions 4.to_f => 4.0 5.to_s => 5 6.to_i => 6 6.to_f => 6.0 utc.to_sym => :utc :utc.to_s => utc 123 apples.to_i => 123 one beer.to_i => 0 22

Error handling begin require rubygems rescue LoadError => ex raise Please install Ruby gems end 23

Object-oriented programming (OOP) 24

Everything is an object Hello world.length 10.times { puts hello world } 10.class 10.class.class 25

class Apple < Fruit Writing a class attr_accessor :color def eat puts A #{color} apple was eaten. end end a = Apple.new a.color = green a.eat 26

Duck typing If it walks like a duck and quacks like a duck, I would call it a duck. 27

Duck typing in real life def eat_something(object) if object.respond_to?(:eat) object.eat else send(:eat) puts Don t know how to eat this. end end 28

Closures arr.sort { a, b a.name <=> b.name } arr.sort_by(&:name) 29

Closures arr = (1..10).to_a => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] arr.find_all { a a % 2 == 0 } => [2, 4, 6, 8, 10] 30

Yield def benchmark start_time = Time.now yield time_diff = Time.now - start_time puts Took #{time_diff} seconds end benchmark { fib(30) } 31

Metaprogramming 32

method_missing class MyFinder def method_missing(method_name) puts I m finding #{method_name} for you! end end m = MyFinder.new m.oranges 33

What if... A database query could be written as: User.find_by_name( Otto Hilska ) That s exactly how it works in Rails. 34

Too exciting! Let s have a short break. 35

Ruby on Rails 36

Background Open-sourced in 2004 Written by David Heinemeier Hansson Extracted from the Basecamp project management software 37

Motivation You can probably write your project in 15 minutes if you know what you re doing. you probably don t Case: tickets.assembly.org 38

Disclaimer 3 hours is not enough Focus on the big picture http://guides.rubyonrails.org/ http://apidock.com/ 39

Design principles Don t Repeat Yourself Convention over Configuration 40

HTTP Browsers send stateless requests Servers may store session information (state) 41

MVC Model stores and processes data contains the re-usable logic View renders data HTML, JavaScript, XML,... Controller processes HTTP requests has the request information and session information available uses models to do the business logic decides which views to render is supposed to be thin 42

Starting a Rails project: % rails myproject 43

Directory structure app controllers helpers models views layouts db migrate schema.rb tmp config database.yml environment* initializers routes.rb lib log public script test vendor 44

Today s example project Mutter my own Twitter clone because 140 chars is too much 45

Now some coding... 46

Summary DRY CoC Did you see any XML? 47

Deployment Many bad alternatives One good: http://www.modrails.com/ 48

Further reading REST clients: rest-client and ActiveResource http://guides.rubyonrails.org/ http://apidock.com/ 49