SlideShare uma empresa Scribd logo
1 de 28
Baixar para ler offline
In Ruby 's arms                            by Tom Waits


 The sexy programming language that will
     change you career as a developer




                                           OpenFest
Look mam, PHP!
                                                  I can makez
                                                  webzitez




There are people who actually like programming.
I don't understand why they like programming.

- Rasmus Lerdorf (creator of php)



                                                             OpenFest 2011
Who am I?



xPHP-er who learned
 Ruby and matured



Founder at Sfalma.com
Partner at NiobiumLabs
    http://6pna.com
       @panosjee
What is special about Ruby?
 Open Source
 Simple (before you dive in the deep)
 Elegant
 Dynamic
 Made for programmers' productivity and sanity
 Modern
 Has a vibrant community
 Huge amount of libraries and framework
 Great VMs (take a look at JRuby)
 Not meant to be server-side only (I look at you php)
 Sexy! (how much sexy?)


                                                OpenFest
Even
Berlusconi
took Ruby
for a spin!
Let 's start from the basic
 Everything is an Object
 Functions (methods) are messages
 Object communicate with messages
 No type casting. Each method should know what is
 expecting. Maybe that 's why Rubyists are so Test
 Paranoid
 Operators are syntactic sugar for methods. You can
 redefine them as well.
 Blocks and Closures (start thinking functionally and
 reach developers' Nirvana)
 Mixins
 IRB (console)
                                                 OpenFest
Open an IRB, load anything, play, explore, learn, debug!
Some Syntactic Sugar
# define a hash
hash = {a: 1, b:2, c:3, d:0, e:9, f:4}
# get key, values that are greater than 3
hash.select{ |k,v| v > 3 }

# multiple all values by 2 and store in new array
new_array = hash.values.map { |v| v * 2 }

# You know now about block and closures!
# Get all odd numbers from 1 to 10 multiplied by 10
1.upto(10).map { |i| i*10 if i.odd? }.compact


                                                    OpenFest
Some Magic Included
# We want a small DSL* that gives us relevant dates
# to today
# Normally we type

now = Time.now
# => 2011-04-09 19:02:22 +0300
# We add the seconds (of a day) to advance in Time
now + 60 * 60 * 24
# => 2011-04-10 19:02:22 +0300
# Not cool enough, let 's see what we can do



                                                 OpenFest
Some Magic Included (II)
# Remember everything is an object that we can
# always overload
class Fixnum
   def days
     self * 60 * 60 * 24
   end
end

# Let 's see what it does
3.days
# => 172800
# the total number of seconds of 3 days

                                                 OpenFest
Some Magic Included (III)
# Let 's reopen and add spell some magic
class Fixnum
   def from_now
     Time.now + self
   end
end

# Let 's see what it does
3.days.from_now
# => 2011-04-12 19:10:45 +0300
# Congratulations! You just created your first DSL


                                                     OpenFest
What the heck is DSL?
DSL = Domain Specific Language

DSLs allow you to create a mini language that
solved specific problem. So instead of expressing
everything in a language made for computers you
can create a language that solves problem *BUT*
humans can understand them too.

The DSL concept was introduced by Lisp. Since
Lisp is only for the enlightened ones you can use
Ruby *TODAY* to create your DSLs.

                                             OpenFest
A wealth of libraries
Installing a library in Ruby is as easier than
getting off your bed:
gem install rails

 Ruby libraries are distributed as gems. You can
 find some millions at http://www.rubygems.org
 and of course study the code (usually at Github).
 Gem commands resemble apt-get of Debian

 Sometimes though libraries have a tendency to
 create nightmares due to dependencies. Bundler
 helps you sleep tight

                                                     OpenFest
Hey I want to learn Rails!
 Hold your horses pow! Rails is a great tools
 but your Rails app will look like PHP if you
 do not learn and master Ruby, the language.

   Most Rails noobs that come from PHP
  continue the PHP attrocities thus creating
           terrible spaggheti code.

Rails will not make you write excellent apps.
Learning, persistence and coding will. So we
     have to master Ruby, the language.
                                         OpenFest
Let 's dive into the Web (Rack)
Have you heard of CGI, FastCGI? You know the old way a
server (Apache) could talk to a script?

Well in Ruby we have Rack. Rack provides a minimal
interface between webservers supporting Ruby and Ruby
frameworks.

Whatever programs sits between our Ruby application and
the server we call it middleware.

Rack enables you to talk HTTP.




                                                  OpenFest
Let 's dive into the Web (Rack)
You can even expose any Ruby object as a Web Service!
BEWARE: Try only at home!
require 'rubygems'
require 'rack'

class Object
 def webapp
   class << self
     define_method :call do |env|
      func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
      [200, {}, send(func, *attrs)]
     end
   end
   self
 end
end

Rack::Handler::Mongrel.run [].webapp, :Port => 8080
# http://localhost:8080/push/1 -> 1
# http://localhost:8080/to_a -> 1




                                                                    OpenFest
* it does not make you a Rock Star
  hard work, love and code'n' roll does
You speak HTTP, now sing HTML
Rails is collection of Ruby libraries that sit on top of Rack
and allow you to create well organized web applications.

Rails started by DHH at 37signals around 2004. At the
beginning it was a very opinionated framework and caused
a tsunami in the web development world. Nowadays most
web frameworks are based on the Rails philosophy.

Rails favors convention over configuration so you should
things the Rails way and stop writing XML files (hey Java-
ers) or spaghetti code (hello PHPers)




                                                        OpenFest
Why do people use Rails?
Rails is magnificent tools for creating Web Applications. If
your main focus is Content Websites of course you can do
great stuff with Rails but you can stick to Drupal.

Some famous Ruby on Rails Web (sites/apps) are:
   Twitter - http://twitter.com
   Groupon - http://www.groupon.com
   Soundcloud - http://www.soundcloud.com
   Github - http://www.github.com
   Basecamp - http://www.basecamphq.com
   Slideshare - http://www.slideshare.com
   Skroutz.gr - http://www.skroutz.gr


                                                      OpenFest
Everything at its place
Rails is an MVC framework. MVC stands for:

   Model, an ORM, a class that talks and abstracts your
   database. We also add logic here. So for example the
   model Person will contain the logic. ex. person.
   write_me_code, person.pay_your_bills
   Controllers, controller will orchestrate your app. They
   take a user 's request spin up some models (if needed)
   collect the results and pass the to the views
   View, the view can be an HTML file, JSON, XML,
   PDF, a mobile friendly HTML page. You name it!




                                                     OpenFest
Stay RESTful!
Rails + REST = L.F.E.

REST stands for Representional State Transfer.
Rails wants you to think in terms of objects.
Your URLs are not pointer to some stupid files:
ex. /edit_category.php?c_id=2

Rails uses all HTTP verbs GET, POST, DELETE, PUT,
HEAD and matches them to a URL. For example.
   GET /category/1 # show category info
   POST /category # creates a category
   PUT /category/1 # updates a category


                                                  OpenFest
1. The user hits the server
                                                                          that talks to Rack. Rack
                                                                          calls the Routes.
                                                                       2. The Routes will match
                                                                          the URL that user asked
                                                                          and dispatch the request
                                                                          data to the Controller.
                                                                       3. The Controller gets the
                                                                          request data and calls
                                                                          the Models (database) if
                                                                          need.
                                                                       4. The model returns data
                                                                       5. The Controller collects
                                                                          the data from the model
                                                                          and spits them to the
                                                                          View.
                                                                       6. The View returns the
                                                                          formatted data (HTML,
                                                                          JSON etc) to the
                                                                          Controller.
                                                                       7. The Controller talks to
                                                                          the Server and gives
http://gmoeck.github.com/2011/03/10/sproutcore-mvc-vs-rails-mvc.html
                                                                          him the web page.
Use the command line
It is easier than what you think. I guess you can understand
the following:
rails new awesome_app
rails generate model Person name:string money:integer
rails generate controller Main index about contact
rails generate scaffold Category name:string



Rails uses migrations to create your database schema. No
more manual changes. If you work in a team there is not
other way to go!
rake db:migrate
rake db:migrate:reset
rake db:seed



                                                        OpenFest
Routes (URLs) to functions not files!
A url is routes to code a function inside a controller. You
can change it a breeze and create meaningful urls:
 Guitar121::Application.routes.draw do

  match "/account" => "users#edit", :as => 'account'
  resources :attachments

  get "courses/missing", :as => :missing_course

  resources :courses do
   resources :attachments
   member do
     get :invite
     put :uninvite
   end
  end
 end



                                                       OpenFest
Bye bye SQL, we won't miss ya!
ActiveRecord (the Model) will abstract the database from
us. You can switch your app from SQLite to Oracle and do
not change any query (hopefully).:
# Get the first user with specific id and rank > 0
User.where(:id=>params[:id], :rank > 10).first

# Get all videos in category 3 order by views
Video.where(:category_id=>3).order("views").all




                                                     OpenFest
Get your hands dirty now!
Probably there are too many new notions and words you
cannot understand the only way to go is get down to write
some code. The Ruby community is very enthousiastic and
active. So head your browser to the following links and
dive into Ruby and Rails:

   http://www.ruby-lang.org/en/
   http://railscasts.com/
   http://railsforzombies.org/
   http://ruby5.envylabs.com/
   http://rubyst.es




                                                    OpenFest
Thank you!
            @panosjee - http://6pna.com

Ruby and Rails are not silver bullets but they can open a window to
better productivity, developer happiness and cool hacks. Use at your
                              own risk!
   You may also learn Python or Node.js just stop using
   PHP!     Special thanx to @Drakevr for fixing my typos!




                                                                 OpenFest

Mais conteúdo relacionado

Mais procurados

Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Shaer Hassan
 
Introduction to "robots.txt
Introduction to "robots.txtIntroduction to "robots.txt
Introduction to "robots.txtIshan Mishra
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortegaarman o
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking systemJesse Vincent
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Coursepeter_marklund
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewLibin Pan
 
Security Goodness with Ruby on Rails
Security Goodness with Ruby on RailsSecurity Goodness with Ruby on Rails
Security Goodness with Ruby on RailsSource Conference
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsManoj Kumar
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to ThriftDvir Volk
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8rajkumar2011
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyistsbobmcwhirter
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Michael Pirnat
 
Introduction to AtomPub Web Services
Introduction to AtomPub Web ServicesIntroduction to AtomPub Web Services
Introduction to AtomPub Web ServicesBen Ramsey
 

Mais procurados (20)

Debugging on rails
Debugging on railsDebugging on rails
Debugging on rails
 
Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
Introduction to "robots.txt
Introduction to "robots.txtIntroduction to "robots.txt
Introduction to "robots.txt
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking system
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
 
Ruby on Rails 2.1 What's New
Ruby on Rails 2.1 What's NewRuby on Rails 2.1 What's New
Ruby on Rails 2.1 What's New
 
Security Goodness with Ruby on Rails
Security Goodness with Ruby on RailsSecurity Goodness with Ruby on Rails
Security Goodness with Ruby on Rails
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jerseyEclipse Day India 2015 - Rest with Java (jax rs) and jersey
Eclipse Day India 2015 - Rest with Java (jax rs) and jersey
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 
Getting started with Django 1.8
Getting started with Django 1.8Getting started with Django 1.8
Getting started with Django 1.8
 
Php go vrooom!
Php go vrooom!Php go vrooom!
Php go vrooom!
 
Perl Intro 6 Ftp
Perl Intro 6 FtpPerl Intro 6 Ftp
Perl Intro 6 Ftp
 
TorqueBox for Rubyists
TorqueBox for RubyistsTorqueBox for Rubyists
TorqueBox for Rubyists
 
RubyGems 3 & 4
RubyGems 3 & 4RubyGems 3 & 4
RubyGems 3 & 4
 
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
Shiny, Let’s Be Bad Guys: Exploiting and Mitigating the Top 10 Web App Vulner...
 
Introduction to AtomPub Web Services
Introduction to AtomPub Web ServicesIntroduction to AtomPub Web Services
Introduction to AtomPub Web Services
 

Semelhante a Ruby openfest

Multi-threaded web crawler in Ruby
Multi-threaded web crawler in RubyMulti-threaded web crawler in Ruby
Multi-threaded web crawler in RubyPolcode
 
14 technologies every web developer should be able to understand
14 technologies every web developer should be able to understand14 technologies every web developer should be able to understand
14 technologies every web developer should be able to understandUm e Farwa
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN StackRob Davarnia
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1nhepner
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on RailsViridians
 
Intro to Rails and MVC
Intro to Rails and MVCIntro to Rails and MVC
Intro to Rails and MVCSarah Allen
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails FinalRobert Postill
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandMatthew Turland
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails SiddheshSiddhesh Bhobe
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction Tran Hung
 
Introduction to REST and Jersey
Introduction to REST and JerseyIntroduction to REST and Jersey
Introduction to REST and JerseyChris Winters
 

Semelhante a Ruby openfest (20)

Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Multi-threaded web crawler in Ruby
Multi-threaded web crawler in RubyMulti-threaded web crawler in Ruby
Multi-threaded web crawler in Ruby
 
.NET RDF APIS
.NET RDF APIS.NET RDF APIS
.NET RDF APIS
 
14 technologies every web developer should be able to understand
14 technologies every web developer should be able to understand14 technologies every web developer should be able to understand
14 technologies every web developer should be able to understand
 
Beginning MEAN Stack
Beginning MEAN StackBeginning MEAN Stack
Beginning MEAN Stack
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Data programing
Data programingData programing
Data programing
 
Web technologies lesson 1
Web technologies   lesson 1Web technologies   lesson 1
Web technologies lesson 1
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
 
Intro to Rails and MVC
Intro to Rails and MVCIntro to Rails and MVC
Intro to Rails and MVC
 
Servlet & jsp
Servlet  &  jspServlet  &  jsp
Servlet & jsp
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
 
Creating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew TurlandCreating Web Services with Zend Framework - Matthew Turland
Creating Web Services with Zend Framework - Matthew Turland
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Rails Concept
Rails ConceptRails Concept
Rails Concept
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
Introduction to REST and Jersey
Introduction to REST and JerseyIntroduction to REST and Jersey
Introduction to REST and Jersey
 

Ruby openfest

  • 1. In Ruby 's arms by Tom Waits The sexy programming language that will change you career as a developer OpenFest
  • 2. Look mam, PHP! I can makez webzitez There are people who actually like programming. I don't understand why they like programming. - Rasmus Lerdorf (creator of php) OpenFest 2011
  • 3. Who am I? xPHP-er who learned Ruby and matured Founder at Sfalma.com Partner at NiobiumLabs http://6pna.com @panosjee
  • 4. What is special about Ruby? Open Source Simple (before you dive in the deep) Elegant Dynamic Made for programmers' productivity and sanity Modern Has a vibrant community Huge amount of libraries and framework Great VMs (take a look at JRuby) Not meant to be server-side only (I look at you php) Sexy! (how much sexy?) OpenFest
  • 6. Let 's start from the basic Everything is an Object Functions (methods) are messages Object communicate with messages No type casting. Each method should know what is expecting. Maybe that 's why Rubyists are so Test Paranoid Operators are syntactic sugar for methods. You can redefine them as well. Blocks and Closures (start thinking functionally and reach developers' Nirvana) Mixins IRB (console) OpenFest
  • 7. Open an IRB, load anything, play, explore, learn, debug!
  • 8. Some Syntactic Sugar # define a hash hash = {a: 1, b:2, c:3, d:0, e:9, f:4} # get key, values that are greater than 3 hash.select{ |k,v| v > 3 } # multiple all values by 2 and store in new array new_array = hash.values.map { |v| v * 2 } # You know now about block and closures! # Get all odd numbers from 1 to 10 multiplied by 10 1.upto(10).map { |i| i*10 if i.odd? }.compact OpenFest
  • 9. Some Magic Included # We want a small DSL* that gives us relevant dates # to today # Normally we type now = Time.now # => 2011-04-09 19:02:22 +0300 # We add the seconds (of a day) to advance in Time now + 60 * 60 * 24 # => 2011-04-10 19:02:22 +0300 # Not cool enough, let 's see what we can do OpenFest
  • 10. Some Magic Included (II) # Remember everything is an object that we can # always overload class Fixnum def days self * 60 * 60 * 24 end end # Let 's see what it does 3.days # => 172800 # the total number of seconds of 3 days OpenFest
  • 11. Some Magic Included (III) # Let 's reopen and add spell some magic class Fixnum def from_now Time.now + self end end # Let 's see what it does 3.days.from_now # => 2011-04-12 19:10:45 +0300 # Congratulations! You just created your first DSL OpenFest
  • 12. What the heck is DSL? DSL = Domain Specific Language DSLs allow you to create a mini language that solved specific problem. So instead of expressing everything in a language made for computers you can create a language that solves problem *BUT* humans can understand them too. The DSL concept was introduced by Lisp. Since Lisp is only for the enlightened ones you can use Ruby *TODAY* to create your DSLs. OpenFest
  • 13. A wealth of libraries Installing a library in Ruby is as easier than getting off your bed: gem install rails Ruby libraries are distributed as gems. You can find some millions at http://www.rubygems.org and of course study the code (usually at Github). Gem commands resemble apt-get of Debian Sometimes though libraries have a tendency to create nightmares due to dependencies. Bundler helps you sleep tight OpenFest
  • 14. Hey I want to learn Rails! Hold your horses pow! Rails is a great tools but your Rails app will look like PHP if you do not learn and master Ruby, the language. Most Rails noobs that come from PHP continue the PHP attrocities thus creating terrible spaggheti code. Rails will not make you write excellent apps. Learning, persistence and coding will. So we have to master Ruby, the language. OpenFest
  • 15. Let 's dive into the Web (Rack) Have you heard of CGI, FastCGI? You know the old way a server (Apache) could talk to a script? Well in Ruby we have Rack. Rack provides a minimal interface between webservers supporting Ruby and Ruby frameworks. Whatever programs sits between our Ruby application and the server we call it middleware. Rack enables you to talk HTTP. OpenFest
  • 16. Let 's dive into the Web (Rack) You can even expose any Ruby object as a Web Service! BEWARE: Try only at home! require 'rubygems' require 'rack' class Object def webapp class << self define_method :call do |env| func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) [200, {}, send(func, *attrs)] end end self end end Rack::Handler::Mongrel.run [].webapp, :Port => 8080 # http://localhost:8080/push/1 -> 1 # http://localhost:8080/to_a -> 1 OpenFest
  • 17. * it does not make you a Rock Star hard work, love and code'n' roll does
  • 18. You speak HTTP, now sing HTML Rails is collection of Ruby libraries that sit on top of Rack and allow you to create well organized web applications. Rails started by DHH at 37signals around 2004. At the beginning it was a very opinionated framework and caused a tsunami in the web development world. Nowadays most web frameworks are based on the Rails philosophy. Rails favors convention over configuration so you should things the Rails way and stop writing XML files (hey Java- ers) or spaghetti code (hello PHPers) OpenFest
  • 19. Why do people use Rails? Rails is magnificent tools for creating Web Applications. If your main focus is Content Websites of course you can do great stuff with Rails but you can stick to Drupal. Some famous Ruby on Rails Web (sites/apps) are: Twitter - http://twitter.com Groupon - http://www.groupon.com Soundcloud - http://www.soundcloud.com Github - http://www.github.com Basecamp - http://www.basecamphq.com Slideshare - http://www.slideshare.com Skroutz.gr - http://www.skroutz.gr OpenFest
  • 20.
  • 21. Everything at its place Rails is an MVC framework. MVC stands for: Model, an ORM, a class that talks and abstracts your database. We also add logic here. So for example the model Person will contain the logic. ex. person. write_me_code, person.pay_your_bills Controllers, controller will orchestrate your app. They take a user 's request spin up some models (if needed) collect the results and pass the to the views View, the view can be an HTML file, JSON, XML, PDF, a mobile friendly HTML page. You name it! OpenFest
  • 22. Stay RESTful! Rails + REST = L.F.E. REST stands for Representional State Transfer. Rails wants you to think in terms of objects. Your URLs are not pointer to some stupid files: ex. /edit_category.php?c_id=2 Rails uses all HTTP verbs GET, POST, DELETE, PUT, HEAD and matches them to a URL. For example. GET /category/1 # show category info POST /category # creates a category PUT /category/1 # updates a category OpenFest
  • 23. 1. The user hits the server that talks to Rack. Rack calls the Routes. 2. The Routes will match the URL that user asked and dispatch the request data to the Controller. 3. The Controller gets the request data and calls the Models (database) if need. 4. The model returns data 5. The Controller collects the data from the model and spits them to the View. 6. The View returns the formatted data (HTML, JSON etc) to the Controller. 7. The Controller talks to the Server and gives http://gmoeck.github.com/2011/03/10/sproutcore-mvc-vs-rails-mvc.html him the web page.
  • 24. Use the command line It is easier than what you think. I guess you can understand the following: rails new awesome_app rails generate model Person name:string money:integer rails generate controller Main index about contact rails generate scaffold Category name:string Rails uses migrations to create your database schema. No more manual changes. If you work in a team there is not other way to go! rake db:migrate rake db:migrate:reset rake db:seed OpenFest
  • 25. Routes (URLs) to functions not files! A url is routes to code a function inside a controller. You can change it a breeze and create meaningful urls: Guitar121::Application.routes.draw do match "/account" => "users#edit", :as => 'account' resources :attachments get "courses/missing", :as => :missing_course resources :courses do resources :attachments member do get :invite put :uninvite end end end OpenFest
  • 26. Bye bye SQL, we won't miss ya! ActiveRecord (the Model) will abstract the database from us. You can switch your app from SQLite to Oracle and do not change any query (hopefully).: # Get the first user with specific id and rank > 0 User.where(:id=>params[:id], :rank > 10).first # Get all videos in category 3 order by views Video.where(:category_id=>3).order("views").all OpenFest
  • 27. Get your hands dirty now! Probably there are too many new notions and words you cannot understand the only way to go is get down to write some code. The Ruby community is very enthousiastic and active. So head your browser to the following links and dive into Ruby and Rails: http://www.ruby-lang.org/en/ http://railscasts.com/ http://railsforzombies.org/ http://ruby5.envylabs.com/ http://rubyst.es OpenFest
  • 28. Thank you! @panosjee - http://6pna.com Ruby and Rails are not silver bullets but they can open a window to better productivity, developer happiness and cool hacks. Use at your own risk! You may also learn Python or Node.js just stop using PHP! Special thanx to @Drakevr for fixing my typos! OpenFest