SlideShare uma empresa Scribd logo
1 de 103
RUBY ON RAILS
   the beginning
ANY IDEAS?
RUBYONRAILS.ORG
RUBY-LANG.ORG
PROGRAMMING
  LANGUAGE    WEB FRAMEWORK
Ruby on Rails is an open-source
web framework that’s optimized
for programmer happiness and
sustainable productivity.

It lets you write beautiful code
by favoring convention over
configuration.
Ruby on Rails is an open-source
web framework that’s optimized
for programmer happiness and
sustainable productivity.

It lets you write beautiful code
by favoring convention over
configuration.
Ruby on Rails is an open-source
web framework that’s optimized
for programmer happiness and
sustainable productivity.

It lets you write beautiful code
by favoring convention over
configuration.
Ruby on Rails is an open-source
web framework that’s optimized
for programmer happiness and
sustainable productivity.

It lets you write beautiful code
by favoring convention over
configuration.
Ruby on Rails is an open-source
web framework that’s optimized
for programmer happiness and
sustainable productivity.

It lets you write beautiful code
by favoring convention over
configuration.
80/20
 Pareto principle
DON’T
REPEAT
YOURSELF
DON’T
REPEAT
YOURSELF
DUPLICATION
IS
EVIL
DUPLICATION
IS
EVIL
RUBY
Why an other
programming
  language?
Some might like this, but it's
 mostly because most Software
Development Tools are designed
 for computers, not for human
            beings.
Some might like this, but it's
 mostly because most Software
Development Tools are designed
 for computers, not for human
            beings.
Some might like this, but it's
 mostly because most Software
Development Tools are designed
 for computers, not for human
            beings.
“Ruby is simple in
appearance, but is
very complex inside,
just like human body”

Yukihiro “Matz” Matsumoto,
Creator of Ruby
MAKE THE
 COMPUTER
WORK FOR YOU
DESIGN THE
LANGUAGE AND
 LIBRARIES FOR
  PEOPLE FIRST
LET OTHERS
 CARE ABOUT
PERFORMANCE
say = “I love Ruby”
puts say

=> “I love Ruby”
say = “I love Ruby”
say[‘love’] = “*love*”
puts say.upcase

=> “I *LOVE* RUBY”
4.times { puts say }

=>   “I   *love*   Ruby”
=>   “I   *love*   Ruby”
=>   “I   *love*   Ruby”
=>   “I   *love*   Ruby”
Time.now + 1.day

=> Fri Jul 30 17:48:05 +0300 2010
Ruby is a dynamic, open source
programming language with a focus
on simplicity and productivity.

It has an elegant syntax that is
natural to read and easy to write.
Ruby is a dynamic, open source
programming language with a focus
on simplicity and productivity.

It has an elegant syntax that is
natural to read and easy to write.
Ruby is a dynamic, open source
programming language with a focus
on simplicity and productivity.

It has an elegant syntax that is
natural to read and easy to write.
Ruby is a dynamic, open source
programming language with a focus
on simplicity and productivity.

It has an elegant syntax that is
natural to read and easy to write.
Ruby is a dynamic, open source
programming language with a focus
on simplicity and productivity.

It has an elegant syntax that is
natural to read and easy to write.
Ruby is a dynamic, open source
programming language with a focus
on simplicity and productivity.

It has an elegant syntax that is
natural to read and easy to write.
Ruby is a dynamic, open source
programming language with a focus
on simplicity and productivity.

It has an elegant syntax that is
natural to read and easy to write.
LESS IS MORE
JAVA
public static String reverseString(String source) {
   int i, len = source.length();
   StringBuffer dest = new StringBuffer(len);
}
for (i = (len - 1); i >= 0; i--)
   dest.append(source.charAt(i));
return dest.toString();

reverseString("Krawutzikapuzi");

=> "izupakiztuwarK"
PHP

strrev("Krawutzikapuzi");

=> "izupakiztuwarK"
RUBY

"Krawutzikapuzi".reverse

=> "izupakiztuwarK"
RUBY


"Krawutzikapuzi".split(//).inject(""){ |m,c| c + m }

=> "izupakiztuwarK"




       Not using the built-in “reverse” method. Still much smaller that Java.
COMPLETE
  OBJECT
ORIENTATION
10.class

=> Fixnum
Fixnum.object_id

=> 108610
(10*10).class

=> Fixnum
(10*10*10*100000).class

=> Bignum
class String
	 def method_missing(method)
	 	 puts "intercepting call to #{method}"
	 end
end

"Lorem ipsum dolor".krawutzikaputzi

=> "intercepting call to krawutzikaputzi"
>> Post.find_by_published(true)

=> #<Post id: 1, title: "Hallo FH!", body:
"Lorem ipsum dolor sit amet, consectetur
adipisicing...", published: true, created_at:
"2008-04-14 12:07:46", updated_at:
"2008-04-14 12:07:46">
>> Post.find_by_published(true)

=> #<Post id: 1, title: "Hallo FH!", body:
"Lorem ipsum dolor sit amet, consectetur
adipisicing...", published: true, created_at:
"2008-04-14 12:07:46", updated_at:
"2008-04-14 12:07:46">
RAILS
MVC
MVC
        (model-view-controller)




            Controller




Model                             View
MVC
        (model-view-controller)




            Controller




Model                             View
MVC
        (model-view-controller)




 DB                               Helper
            Controller




Model                             View
REST
IN THE BEGINNING
THERE WAS THE URL
http://pluspoker.true-vision.net/content/index.html
http://www.merriam-webster.com/cgi-bin/mwwod.pl
http://gilesbowkett.blogspot.com/search?updated-
max=2008-04-08T09%3A25%3A00-07%3A00&max-results=7
http://www.amazon.de/gp/ product/B0000262LH/ ref=s9subs_c3_img1-
rfc_p_19_32_31_9_9? pf_rd_m=A1IDDPBG1NC5TQ&pf_rd_
s=center-2&pf_rd_r=1FMGVYJN44 H7WQD9YCR9&pf_rd_t=101&pf_rd_
p=139524591&pf_rd_i=301128
REST
(Representational State Transfer)
WEB APPLICATION
USUALLY CONSISTS
   OF OBJECTS
(like, say, blog posts)
WHAT IS A BLOG POST?
BLOG POST



It’s an entry in a database.
Consists of title, body, date,
       and other data.
HTML REPRESENTATION




 http://0.0.0.0:3000/posts/1
XML REPRESENTATION
<?xml version=“1.0” encoding=“UTF-8”?>
<post>
   <id type=“integer”>1</id>
   <title>Another title</title>
   <body>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
   eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
   minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
   ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
   velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
   cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id
   est laborum.</body>
   <created-at type=“datetime”>2008-04-14T12:07:46+02:00</created-at>
   <published type=“boolean”>true</published>
   <updated-at type=“datetime”>2008-04-15T11:30:50+02:00</updated-at>
   <version type=“integer”>2</version>
</post>




    http://0.0.0.0:3000/posts/1.xml
def show
  @post =
  Post.find(params[:id])respond_to do |
  format|
    format.html
    format.xml { render :xml => @post }
  end
end
RESTFUL OPERATIONS


      • create

      • read

      • update

      • delete
HTTP VERBS
in HTTP each request is preceeded
    by a request type, or “verb”.
Normal page loads use the “GET” verb,
   while web forms use “POST”.
HTTP knows more verbs, most
importantly “PUT” and “DELETE”.
REST operation   HTTP verb


   Create          POST
    Read            GET
   Update           PUT
   Delete         DELETE
GET   http://localhost:3000/posts/1
DELETE   http://localhost:3000/posts/1
GET     http://localhost:3000/posts
 GET     http://localhost:3000/posts/1
 POST     http://localhost:3000/posts
 PUT     http://localhost:3000/posts/1
DELETE    http://localhost:3000/posts/1
The best thing is
that Rails does it all
    completely
   automatically.
ROUTING
map.resources :posts
map.sign_up 'sign_up/', :controller => 'registrations', :action => 'new'




              GET http://localhost:3000/sign_up/
map.resources :videos do |videos|
  videos.resources :comments
  videos.like '/like', :controller => 'favorites', :action => 'create'
end

map.resources :poker_rooms, :member => { :move_up => :get, :move_down => :get }
map.resources :favorites
map.resources :users

map.sign_up 'sign_up/', :controller => 'registrations', :action => 'new'
map.edit_registration 'user/edit', :controller => 'registrations', :action => 'edit'
map.sign_in 'sign_in/', :controller => 'sessions', :action => 'new'
map.sign_out 'sign_out/', :controller => 'sessions', :action => 'destroy'

map.resources :registrations, :only => [ :create, :update, :destroy ]
map.resources :sessions, :only => [ :create, :destroy ]

map.root :controller => 'videos', :action => 'preview'
ORM
(OBJECT RELATIONAL MAPPING)
Post.find 1
Post.find 1

SELECT * FROM posts
 WHERE posts.id = 1
       LIMIT 1
Post.find_all_by_title ‘Hello World’


       SELECT * FROM posts
WHERE posts.title = ‘Hello World’
class Post < ActiveRecord::Base
  belongs_to :user
end




class User < ActiveRecord::Base
  has_many :posts
end
@user = User.first

SELECT * FROM users LIMIT 1



      @user.posts
 SELECT * FROM posts WHERE
     posts.user_id = 1
GENERATORS
rails pluspoker
script/generate model user username:string age:integer
script/generate controller users
script/generate migration add_active_to_users active:boolean
NEED MORE?
WRITE YOU OWN!
RAILS IS 100% RUBY-WRITTEN
MONGREL
MONGREL


• Very    lightweight

• Single   request server

• Ideal   for local use
Browser   Mongrel
SERVER SIDE
Mongrel



                   Mongrel
          Apache
Browser
           nginx
                   Mongrel



                   Mongrel
Thread



                               Thread



                               ...
          Apache   Passenger
Browser
           nginx   mod_rails
Q&A

Mais conteúdo relacionado

Mais procurados

AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
clkao
 
Socket applications
Socket applicationsSocket applications
Socket applications
João Moura
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
Tatsuhiko Miyagawa
 

Mais procurados (20)

Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
AnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time webAnyMQ, Hippie, and the real-time web
AnyMQ, Hippie, and the real-time web
 
Ajax Security
Ajax SecurityAjax Security
Ajax Security
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Socket applications
Socket applicationsSocket applications
Socket applications
 
Djangocon 2014 angular + django
Djangocon 2014 angular + djangoDjangocon 2014 angular + django
Djangocon 2014 angular + django
 
Mojolicious and REST
Mojolicious and RESTMojolicious and REST
Mojolicious and REST
 
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 MinutesDjangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
 
Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3Real time web (Orbited) at BCNE3
Real time web (Orbited) at BCNE3
 
Express JS
Express JSExpress JS
Express JS
 
Master the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and SilexMaster the New Core of Drupal 8 Now: with Symfony and Silex
Master the New Core of Drupal 8 Now: with Symfony and Silex
 
Plack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and serversPlack perl superglue for web frameworks and servers
Plack perl superglue for web frameworks and servers
 
Symfony2 and AngularJS
Symfony2 and AngularJSSymfony2 and AngularJS
Symfony2 and AngularJS
 
Tornado web
Tornado webTornado web
Tornado web
 
CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009CouchDB for Web Applications - Erlang Factory London 2009
CouchDB for Web Applications - Erlang Factory London 2009
 

Destaque (6)

Lean Startup
Lean StartupLean Startup
Lean Startup
 
Test-driven development (Anton Dmitriyev)
Test-driven development (Anton Dmitriyev)Test-driven development (Anton Dmitriyev)
Test-driven development (Anton Dmitriyev)
 
Type Presentation (Alexey Murashko)
Type Presentation (Alexey Murashko)Type Presentation (Alexey Murashko)
Type Presentation (Alexey Murashko)
 
Фокус-Покус (Jean Mauris)
Фокус-Покус (Jean Mauris)Фокус-Покус (Jean Mauris)
Фокус-Покус (Jean Mauris)
 
Back to School
Back to SchoolBack to School
Back to School
 
Клиент всегда (не) прав (Jean Mauris)
Клиент всегда (не) прав (Jean Mauris)Клиент всегда (не) прав (Jean Mauris)
Клиент всегда (не) прав (Jean Mauris)
 

Semelhante a Rails Presentation (Anton Dmitriyev)

SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
Sébastien Levert
 

Semelhante a Rails Presentation (Anton Dmitriyev) (20)

Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
Mobile Development integration tests
Mobile Development integration testsMobile Development integration tests
Mobile Development integration tests
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutes
 
Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)Serverless in production, an experience report (LNUG)
Serverless in production, an experience report (LNUG)
 
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
 
Intro to Rails
Intro to RailsIntro to Rails
Intro to Rails
 
Automatisation in development and testing - within budget
Automatisation in development and testing - within budgetAutomatisation in development and testing - within budget
Automatisation in development and testing - within budget
 
Crossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end FrameworkCrossing the Bridge: Connecting Rails and your Front-end Framework
Crossing the Bridge: Connecting Rails and your Front-end Framework
 
Road to Rails
Road to RailsRoad to Rails
Road to Rails
 
Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)
 
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure FunctionsSharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
SharePoint Fest Seattle - SharePoint Framework, Angular & Azure Functions
 
Mojolicious - A new hope
Mojolicious - A new hopeMojolicious - A new hope
Mojolicious - A new hope
 
Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)Serverless in Production, an experience report (cloudXchange)
Serverless in Production, an experience report (cloudXchange)
 
AWS Lambda from the trenches
AWS Lambda from the trenchesAWS Lambda from the trenches
AWS Lambda from the trenches
 
TPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and FluxTPSE Thailand 2015 - Rethinking Web with React and Flux
TPSE Thailand 2015 - Rethinking Web with React and Flux
 
Serverless in Production, an experience report (AWS UG South Wales)
Serverless in Production, an experience report (AWS UG South Wales)Serverless in Production, an experience report (AWS UG South Wales)
Serverless in Production, an experience report (AWS UG South Wales)
 
Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)Serverless in production, an experience report (London DevOps)
Serverless in production, an experience report (London DevOps)
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 

Último

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Rails Presentation (Anton Dmitriyev)

Notas do Editor