SlideShare a Scribd company logo
1 of 38
Download to read offline
Sumeru
On Rails
Make your own Rails frame work
By: Pankaj Bhageria
Tech Lead
Sumeru Software Solutions
Website: sumeruonrails.com
Blog: railsguru.org
3 Questions ?
Have you ever thought of creating
your own Web Framework?
3 Questions ?
Have you contributed to the Rails
community?
3 Questions ?
Have you ever peeped through the source
code of Rails Framework?
Why Am I here?
It is my vision to have India contribute
significantly to the Rails world.
What stops you from this?
 Fear factor
 Understanding
 Critics
 Results
Objectives
To inspire you, so that, you start
 Contributing to Rails
 Start writing your own gems
 Doing your own experiments
 Start thinking big
 Talk at the next Rubyconf
Minimum Qualification
Basic knowledge of Ruby and Rails.
Over Qualification
 If you are a guru in Ruby and Rails
 If you are already contributing to Rails and open source.
 If you have built some frameworks.
A journey of a thousand miles begins
with a single step.
Lao-tzu Chinese philosopher (604 BC - 531 BC)
The Single Step
 We will build a basic web server and demonstrate
 Routing
 Controllers and Action
 Views
Understanding RACK
WEB SERVER WEB APPLICATION
Hey I got a
Request
/login
Response
[200,header,”Login Form”]
Request
/login
Response
“Login Form”
Understanding RACK
WEB SERVER WEB APPLICATION
Multiple WEB SERVERS
MONGREL
WEBRICK
PASSENGER
THIN
DUPLICATION
Understanding RACK
WEB SERVER WEB APPLICATION
Need a Savior
Understanding RACK
WEB SERVER WEB APPLICATIONRACK
What is a Framework?
A framework is a library which makes writing web applications faster
RACK WEB APPLICATION
Web
Framework
Developer
Code
Integrating with Rack
 To communicate with Rack, the web application should be
a ruby object which respond to a call method
 The Call method should
 Accept a key value pair
 Return an array [status, header, body]
Integrating with Rack
# myserver.rb
class MyServer
def call(env)
[200,{"content-type"=>"text/html"},“Login Here"]
end
end
Integrating with Rack
#config.ru
require "rack“
require “myserver“
run MyServer.new
To run the server we do
rackup config.ru –p 3000Login Here
Integrating with Rack
 We have now a functional
Web Application which can
communicate to Rack.
Lets see what Rack Sends To Webserver
# myserver.rb
class MyServer
def call(env)
[200,{"content-type"=>"text/html"},env.inspect]
end
End
A look at the request
http://localhost:3001/login?username=pankaj
{"HTTP_HOST"=>"localhost:3001",
"HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"SERVER_NAME"=>"localhost", "REQUEST_PATH"=>"/login", "rack.url_scheme"=>"http",
"HTTP_KEEP_ALIVE"=>"300", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB;
rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7", "REMOTE_HOST"=>"SAMLP05110000", "rack.errors"=>#>,
"HTTP_ACCEPT_LANGUAGE"=>"en-gb,en;q=0.5", "SERVER_PROTOCOL"=>"HTTP/1.1",
"rack.version"=>[1, 1], "rack.run_once"=>false, "SERVER_SOFTWARE"=>"WEBrick/1.3.1
(Ruby/1.8.7/2011-02-18)", "REMOTE_ADDR"=>"127.0.0.1", "PATH_INFO"=>"/login",
"SCRIPT_NAME"=>"", "HTTP_VERSION"=>"HTTP/1.1", "rack.multithread"=>true,
"rack.multiprocess"=>false, "REQUEST_URI"=>"http://localhost:3001/login?username=pankaj",
"HTTP_ACCEPT_CHARSET"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.7", "SERVER_PORT"=>"3001",
"REQUEST_METHOD"=>"GET", "rack.input"=>#>, "HTTP_ACCEPT_ENCODING"=>"gzip,deflate",
"HTTP_CONNECTION"=>"keep-alive", "QUERY_STRING"=>"username=pankaj",
"GATEWAY_INTERFACE"=>"CGI/1.1"}
Lets Add some routing
 Mapping the request path(url) to the corresponding action and
controller is routing
 /login => controller:Sessions, action: new
 /logout => controller:Sessions, action: destroy
Define Routes
DEVCODE
#routes
match "/login"=>"sessions#new“
match "/home"=>“home#index"
Define Routes
class MyServer
@@routes_collection = []
..
def self.match(route)
@@routes_collection << MyRoute.new(route)
end
end
Framework: route
class MyRoute
attr_accessor :path, :controller, :action
def initialize(options)
path = options.keys[0]
x = options.values[0].split(“#”)
controller = x[0]
action = x[1]
end
def match(match_path)
path == match_path
end
end
Framework: map_routes
class MyServer
def map_routes(path)
@@routes_collection.each do |route|
if route.match (path)
return route.controller, route.action
break
end
….
end
end
Lets Define Controllers and Action
class HomeController
def index
“Home Page"
end
end
class SessionsController
def new
"login here"
end
end
Revision
# myserver.rb
class MyServer
def call(env)
[200,{"content-type"=>"text/html"},“Login Here"]
end
end
# “Login Here “
# SessionsController
# “sessions”, “new”
# /login
Putting it together
class MyServer
def call(env)
path = env["PATH_INFO"]
controller,action = map_routes(path)
if controller
controller_name = controller_name (controller)
body = eval( "#{controller_name}.new.#{action}" )
else
body = ["Page not found"]
end
status = 200
header = {"content-type"=>"text/html"}
[status,header,body]
end
end
Login Here
Lets Render Some views:
require 'erubis'
class MyActionController
def render(options)
@status = 200
if options[:text]
@body = options[:text]
elsif options[:file]
@body = render_erb_file(views + options[:file] + .erb)
end
end
def render_erb_file(file)
input = File.read(file)
eruby = Erubis::Eruby.new(input)
@body = eruby.result(binding())
end
end
Use render :text
class SessionsController < MyActionController
def new
render :text=>”Login Here, from render text”
end
end
Use render :file
class SessionsController < MyActionController
def new
render :file=>”sessions/new”
end
end
#view file: sessions/new.erb
<p>Login Page. This content is coming from file
sessions/new.rb </p>
End of our first step
 We have built a basic web server and covered the
following features
 Routing
 Controllers and Action
 Views
Where do you go from here
Where do you go from here
 Start, do not wait
 Start looking at rails code
 Start developing your gems
 Start writing your blogs
 Form groups and meetup monthly and share your
knowledge.
 Look at others code.
 Contact me at pankaj.bhageria@sumerusolutions.com
Take Away
You must believe
Any Queries?
Thank you
Need Ruby/Rails training? Contact us at rails@sumerusolutions.com

More Related Content

What's hot

Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - IntroductionVagmi Mudumbai
 
Consuming & embedding external content in WordPress
Consuming & embedding external content in WordPressConsuming & embedding external content in WordPress
Consuming & embedding external content in WordPressAkshay Raje
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le WagonAlex Benoit
 
Put a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastPut a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastOSCON Byrum
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Fwdays
 
Don't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaDon't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaPierre-André Vullioud
 
Phoenix demysitify, with fun
Phoenix demysitify, with funPhoenix demysitify, with fun
Phoenix demysitify, with funTai An Su
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development EnvironmentsBeau Lebens
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with RackDonSchado
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumJeroen van Dijk
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaRoy Sivan
 
Elixir と Maru で REST API
Elixir と Maru で REST APIElixir と Maru で REST API
Elixir と Maru で REST APIKohei Kimura
 
Perl in the Real World
Perl in the Real WorldPerl in the Real World
Perl in the Real WorldOpusVL
 
Building an API using Grape
Building an API using GrapeBuilding an API using Grape
Building an API using Grapevisnu priya
 

What's hot (20)

Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Consuming & embedding external content in WordPress
Consuming & embedding external content in WordPressConsuming & embedding external content in WordPress
Consuming & embedding external content in WordPress
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
Put a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going FastPut a Button on It: Removing Barriers to Going Fast
Put a Button on It: Removing Barriers to Going Fast
 
Rack
RackRack
Rack
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
Don't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaDon't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and Joomla
 
Phoenix demysitify, with fun
Phoenix demysitify, with funPhoenix demysitify, with fun
Phoenix demysitify, with fun
 
Pundit
PunditPundit
Pundit
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
 
ApacheCon 2005
ApacheCon 2005ApacheCon 2005
ApacheCon 2005
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in Titanium
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmia
 
Elixir と Maru で REST API
Elixir と Maru で REST APIElixir と Maru で REST API
Elixir と Maru で REST API
 
Rails::Engine
Rails::EngineRails::Engine
Rails::Engine
 
Perl in the Real World
Perl in the Real WorldPerl in the Real World
Perl in the Real World
 
Building an API using Grape
Building an API using GrapeBuilding an API using Grape
Building an API using Grape
 
Rails Engines
Rails EnginesRails Engines
Rails Engines
 

Viewers also liked

Illusioneo Poesia
Illusioneo PoesiaIllusioneo Poesia
Illusioneo Poesiaguestfd5903
 
A 4th Of July Walk Aka Drive Thru
A 4th Of July Walk Aka Drive ThruA 4th Of July Walk Aka Drive Thru
A 4th Of July Walk Aka Drive ThruLeslie
 
Search in JSON arrays using where and select js
Search in JSON arrays using where and select jsSearch in JSON arrays using where and select js
Search in JSON arrays using where and select jsPankaj Bhageria
 
Informazione Geografica, Città, Smartness
Informazione Geografica, Città, Smartness Informazione Geografica, Città, Smartness
Informazione Geografica, Città, Smartness Beniamino Murgante
 
Nobackend Parse and Dodo
Nobackend Parse and DodoNobackend Parse and Dodo
Nobackend Parse and DodoPankaj Bhageria
 

Viewers also liked (8)

Illusioneo Poesia
Illusioneo PoesiaIllusioneo Poesia
Illusioneo Poesia
 
Lezionidivita
LezionidivitaLezionidivita
Lezionidivita
 
A 4th Of July Walk Aka Drive Thru
A 4th Of July Walk Aka Drive ThruA 4th Of July Walk Aka Drive Thru
A 4th Of July Walk Aka Drive Thru
 
Search in JSON arrays using where and select js
Search in JSON arrays using where and select jsSearch in JSON arrays using where and select js
Search in JSON arrays using where and select js
 
Informazione Geografica, Città, Smartness
Informazione Geografica, Città, Smartness Informazione Geografica, Città, Smartness
Informazione Geografica, Città, Smartness
 
Cartelli
CartelliCartelli
Cartelli
 
Reactjs workshop
Reactjs workshopReactjs workshop
Reactjs workshop
 
Nobackend Parse and Dodo
Nobackend Parse and DodoNobackend Parse and Dodo
Nobackend Parse and Dodo
 

Similar to Ruby conf 2011, Create your own rails framework

Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareAlona Mekhovova
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCalderaLearn
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
Ruby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsRuby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsEmad Elsaid
 
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
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails DevsDiacode
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stackPaul Bearne
 
Rails missing features
Rails missing featuresRails missing features
Rails missing featuresAstrails
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseAaron Silverman
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyNick Sieger
 

Similar to Ruby conf 2011, Create your own rails framework (20)

Mini Rails Framework
Mini Rails FrameworkMini Rails Framework
Mini Rails Framework
 
Intro to Rack
Intro to RackIntro to Rack
Intro to Rack
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Ruby on rails3 - introduction to rails
Ruby on rails3 - introduction to railsRuby on rails3 - introduction to rails
Ruby on rails3 - introduction to rails
 
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
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Rack
RackRack
Rack
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Rails missing features
Rails missing featuresRails missing features
Rails missing features
 
Node.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash CourseNode.js & Twitter Bootstrap Crash Course
Node.js & Twitter Bootstrap Crash Course
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Connecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRubyConnecting the Worlds of Java and Ruby with JRuby
Connecting the Worlds of Java and Ruby with JRuby
 
Dev streams2
Dev streams2Dev streams2
Dev streams2
 

Recently uploaded

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Ruby conf 2011, Create your own rails framework

  • 1. Sumeru On Rails Make your own Rails frame work By: Pankaj Bhageria Tech Lead Sumeru Software Solutions Website: sumeruonrails.com Blog: railsguru.org
  • 2. 3 Questions ? Have you ever thought of creating your own Web Framework?
  • 3. 3 Questions ? Have you contributed to the Rails community?
  • 4. 3 Questions ? Have you ever peeped through the source code of Rails Framework?
  • 5. Why Am I here? It is my vision to have India contribute significantly to the Rails world.
  • 6. What stops you from this?  Fear factor  Understanding  Critics  Results
  • 7. Objectives To inspire you, so that, you start  Contributing to Rails  Start writing your own gems  Doing your own experiments  Start thinking big  Talk at the next Rubyconf
  • 9. Over Qualification  If you are a guru in Ruby and Rails  If you are already contributing to Rails and open source.  If you have built some frameworks.
  • 10. A journey of a thousand miles begins with a single step. Lao-tzu Chinese philosopher (604 BC - 531 BC)
  • 11. The Single Step  We will build a basic web server and demonstrate  Routing  Controllers and Action  Views
  • 12. Understanding RACK WEB SERVER WEB APPLICATION Hey I got a Request /login Response [200,header,”Login Form”] Request /login Response “Login Form”
  • 13. Understanding RACK WEB SERVER WEB APPLICATION Multiple WEB SERVERS MONGREL WEBRICK PASSENGER THIN DUPLICATION
  • 14. Understanding RACK WEB SERVER WEB APPLICATION Need a Savior
  • 15. Understanding RACK WEB SERVER WEB APPLICATIONRACK
  • 16. What is a Framework? A framework is a library which makes writing web applications faster RACK WEB APPLICATION Web Framework Developer Code
  • 17. Integrating with Rack  To communicate with Rack, the web application should be a ruby object which respond to a call method  The Call method should  Accept a key value pair  Return an array [status, header, body]
  • 18. Integrating with Rack # myserver.rb class MyServer def call(env) [200,{"content-type"=>"text/html"},“Login Here"] end end
  • 19. Integrating with Rack #config.ru require "rack“ require “myserver“ run MyServer.new To run the server we do rackup config.ru –p 3000Login Here
  • 20. Integrating with Rack  We have now a functional Web Application which can communicate to Rack.
  • 21. Lets see what Rack Sends To Webserver # myserver.rb class MyServer def call(env) [200,{"content-type"=>"text/html"},env.inspect] end End
  • 22. A look at the request http://localhost:3001/login?username=pankaj {"HTTP_HOST"=>"localhost:3001", "HTTP_ACCEPT"=>"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "SERVER_NAME"=>"localhost", "REQUEST_PATH"=>"/login", "rack.url_scheme"=>"http", "HTTP_KEEP_ALIVE"=>"300", "HTTP_USER_AGENT"=>"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7", "REMOTE_HOST"=>"SAMLP05110000", "rack.errors"=>#>, "HTTP_ACCEPT_LANGUAGE"=>"en-gb,en;q=0.5", "SERVER_PROTOCOL"=>"HTTP/1.1", "rack.version"=>[1, 1], "rack.run_once"=>false, "SERVER_SOFTWARE"=>"WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)", "REMOTE_ADDR"=>"127.0.0.1", "PATH_INFO"=>"/login", "SCRIPT_NAME"=>"", "HTTP_VERSION"=>"HTTP/1.1", "rack.multithread"=>true, "rack.multiprocess"=>false, "REQUEST_URI"=>"http://localhost:3001/login?username=pankaj", "HTTP_ACCEPT_CHARSET"=>"ISO-8859-1,utf-8;q=0.7,*;q=0.7", "SERVER_PORT"=>"3001", "REQUEST_METHOD"=>"GET", "rack.input"=>#>, "HTTP_ACCEPT_ENCODING"=>"gzip,deflate", "HTTP_CONNECTION"=>"keep-alive", "QUERY_STRING"=>"username=pankaj", "GATEWAY_INTERFACE"=>"CGI/1.1"}
  • 23. Lets Add some routing  Mapping the request path(url) to the corresponding action and controller is routing  /login => controller:Sessions, action: new  /logout => controller:Sessions, action: destroy
  • 25. Define Routes class MyServer @@routes_collection = [] .. def self.match(route) @@routes_collection << MyRoute.new(route) end end
  • 26. Framework: route class MyRoute attr_accessor :path, :controller, :action def initialize(options) path = options.keys[0] x = options.values[0].split(“#”) controller = x[0] action = x[1] end def match(match_path) path == match_path end end
  • 27. Framework: map_routes class MyServer def map_routes(path) @@routes_collection.each do |route| if route.match (path) return route.controller, route.action break end …. end end
  • 28. Lets Define Controllers and Action class HomeController def index “Home Page" end end class SessionsController def new "login here" end end
  • 29. Revision # myserver.rb class MyServer def call(env) [200,{"content-type"=>"text/html"},“Login Here"] end end
  • 30. # “Login Here “ # SessionsController # “sessions”, “new” # /login Putting it together class MyServer def call(env) path = env["PATH_INFO"] controller,action = map_routes(path) if controller controller_name = controller_name (controller) body = eval( "#{controller_name}.new.#{action}" ) else body = ["Page not found"] end status = 200 header = {"content-type"=>"text/html"} [status,header,body] end end Login Here
  • 31. Lets Render Some views: require 'erubis' class MyActionController def render(options) @status = 200 if options[:text] @body = options[:text] elsif options[:file] @body = render_erb_file(views + options[:file] + .erb) end end def render_erb_file(file) input = File.read(file) eruby = Erubis::Eruby.new(input) @body = eruby.result(binding()) end end
  • 32. Use render :text class SessionsController < MyActionController def new render :text=>”Login Here, from render text” end end
  • 33. Use render :file class SessionsController < MyActionController def new render :file=>”sessions/new” end end #view file: sessions/new.erb <p>Login Page. This content is coming from file sessions/new.rb </p>
  • 34. End of our first step  We have built a basic web server and covered the following features  Routing  Controllers and Action  Views
  • 35. Where do you go from here
  • 36. Where do you go from here  Start, do not wait  Start looking at rails code  Start developing your gems  Start writing your blogs  Form groups and meetup monthly and share your knowledge.  Look at others code.  Contact me at pankaj.bhageria@sumerusolutions.com
  • 38. Any Queries? Thank you Need Ruby/Rails training? Contact us at rails@sumerusolutions.com