+ All Categories
Transcript
Page 1: fast prototyping with sinatra sequel w2tags

SINATRASINATRASEQUELSEQUELW2TAGSW2TAGS

Page 2: fast prototyping with sinatra sequel w2tags

➢WorkWork: : SKYEIGHTSKYEIGHT ( (S8S8))

➢AtAt--WorkWork: : monorailsmonorails//NETNET 2.02.0

➢OOututsideside--WorkWork: : rubyruby//javascriptjavascript

Page 3: fast prototyping with sinatra sequel w2tags
Page 4: fast prototyping with sinatra sequel w2tags

Sinatradon't doMagic

Page 5: fast prototyping with sinatra sequel w2tags

SinatraSinatra basicbasic ConceptConcept

ThrowThrow URLURL DODO Some StuffSome Stuff

Page 6: fast prototyping with sinatra sequel w2tags

require 'rubygems'require 'sinatra'

get '/' do 'Hello World' end

ThrowThrow URLURL DODO Some StuffSome Stuff

Page 7: fast prototyping with sinatra sequel w2tags

DODO Some StuffSome StuffThrowThrow

ControllerController

Return stringReturn stringURLURL

require 'rubygems'require 'sinatra'

get '/' do 'Hello World' end

Page 8: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sinatra'

get '/' do @data = 'Hello World' erb :index

endindex.erbindex.erb

<%= @data %>

ViewView

Return stringReturn stringURLURL ControllerController

Page 9: fast prototyping with sinatra sequel w2tags

SimplySinatraSequel

Page 10: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sequel' require 'sinatra' DB = Sequel.connect(....) class Entry < Sequel::Model end get '/' do

@recs = Entry.allerb :index

endindex.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>

Page 11: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sequel' require 'sinatra' DB = Sequel.connect(....) class Entry < Sequel::Model end get '/' do

@recs = Entry.allerb :index

endindex.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>

MModelodel

Page 12: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sequel' require 'sinatra' DB = Sequel.connect(....) class Entry < Sequel::Model end get '/' do

@recs = Entry.allerb :index

endindex.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>

MModelodel

VView iew

Page 13: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sequel' require 'sinatra' DB = Sequel.connect(....) class Entry < Sequel::Model end get '/' do

@recs = Entry.allerb :index

endindex.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>

MModelodel

VView iew

CControllerontroller

Page 14: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sequel' require 'sinatra' DB = Sequel.connect(....) class Entry < Sequel::Model end get '/' do

@recs = Entry.allerb :index

endindex.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>

MModelodel

VView iew

CControllerontrollerRRououtete

Page 15: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sequel' require 'sinatra' DB = Sequel.connect(....) class Entry < Sequel::Model end get '/' do

@recs = Entry.allerb :index

endindex.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>

MModelodel

VView iew

CControllerontrollerRRououtete

MVC MVC - - RRSome StuffSome Stuff

Page 16: fast prototyping with sinatra sequel w2tags

SimplySinatraSequelW2Tags

Page 17: fast prototyping with sinatra sequel w2tags

require 'rubygems' require 'sequel' require 'sinatra' require 'w2tags' require 'w2tags/sinatra_hook'

DB = Sequel.connect(....) class Entry < Sequel::Model end get '/' do

@recs = Entry.allerb :index

end

index.w2erbindex.w2erb

%h1%h1 Entry List-each-each @recs;r == r.title %br/%br/

index.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>

Auto G

enerate

Auto G

enerate

Page 18: fast prototyping with sinatra sequel w2tags

index.w2erbindex.w2erb

%h1%h1 Entry List-each-each @recs;r == r.title %br/%br/

index.erbindex.erb

<h1>Entry List</h1><% @recs.each do |r| %> <%= r.title %> <br/><% end %>See the flow

clearly

W2Tags

Page 19: fast prototyping with sinatra sequel w2tags

E n t r yAction Method 1 Method 2

ListNewEdit

Delete

get '/entries'get '/entries/new' post '/entries/new'get '/entries/:id' put '/entries/:id'

delete '/entries/:id'

SinatraSinatracrudcrud

Page 20: fast prototyping with sinatra sequel w2tags

E n t r yAction Method 1 Method 2

ListNewEdit

Delete

get '/entries'get '/entries/new' post '/entries/new'get '/entries/:id' put '/entries/:id'

delete '/entries/:id'

get '/entries' doerb :entries_index

get '/entries/new' doerb :entries_new

post '/entries/new' doredirect '/entries'

get '/entries/:id' doerb :entries_edit

put '/entries/:id' doredirect '/entries'

delete '/entries/:id' doredirect '/entries'

SinatraSinatracrudcrud

11

22

33

Page 21: fast prototyping with sinatra sequel w2tags

Sinatra Sinatra crudcrud

DisplayDisplay ActionAction

Page 22: fast prototyping with sinatra sequel w2tags

SinatraSinatraSimplySimplyMagicMagic

Page 23: fast prototyping with sinatra sequel w2tags
Page 24: fast prototyping with sinatra sequel w2tags
Page 25: fast prototyping with sinatra sequel w2tags
Page 26: fast prototyping with sinatra sequel w2tags

W2TagsW2TagsSimplySimplyMagicMagic

11 22 33

Page 27: fast prototyping with sinatra sequel w2tags

Auto GenerateAuto Generate11

Page 28: fast prototyping with sinatra sequel w2tags

Auto GenerateAuto Generate11

Page 29: fast prototyping with sinatra sequel w2tags

Auto GenerateAuto Generate22

Page 30: fast prototyping with sinatra sequel w2tags

Auto GenerateAuto Generate33

Page 31: fast prototyping with sinatra sequel w2tags

Sinatra Sinatra :: http:/github.com/bmizerany/http:/github.com/bmizerany/sinatrasinatra SequelSequel :: http:/github.com/jeremyevans/http:/github.com/jeremyevans/sequelsequel W2TagsW2Tags :: http:/github.com/wharsojo/http:/github.com/wharsojo/w2tagsw2tags DemoDemo :: http:/github.com/wharsojo/http:/github.com/wharsojo/demo_sinatrademo_sinatra

ResourcesResources

Thank you!Thank you!slideshare.com/wharsojo...slideshare.com/wharsojo...

Page 32: fast prototyping with sinatra sequel w2tags

When error doWhen error doSinatra.applicationSinatra.application.error.erroror selector select .errors.errors

rackrack

Ec = New EventContexEc = New EventContex●Ec.request = New Rack::RequestEc.request = New Rack::Request●Ec.response = New Rack::ResponseEc.response = New Rack::Response

Lookup EventLookup Event ((post,delete,put,get,headpost,delete,put,get,head) or) or

do/raise error do/raise error not_foundnot_found

RenderRender● W2Tags/ErbW2Tags/Erb● Haml, SassHaml, Sass● BuilderBuilder

beforebefore Sinatra.application.filters

Sinatra.application.events

Array ofcode-blockall will beexecute

Array ofcode-blockfirst match

will beexecute

Code-block/render Execute inside instance object ofEventContext

wh/id-ruby

Page 33: fast prototyping with sinatra sequel w2tags

erb.hoterb.hot

Page 34: fast prototyping with sinatra sequel w2tags

sinatra_table.hotsinatra_table.hot

1122

33

44

11

22

33

44

55

55

66

66

77

77

88

88

99

1010

99

1010

1111

1111

1212

1212

11

Page 35: fast prototyping with sinatra sequel w2tags

sinatra_form2.hotsinatra_form2.hot

Page 36: fast prototyping with sinatra sequel w2tags

DBDB[[:tabel:tabel]] #Dataset chainable method, return:Dataset #Dataset chainable method, return:Datasetwherewhere, , filterfilter, , excludeexclude, , orderorder, , reverse_orderreverse_order, , uniquniq, , limitlimit,,paginatepaginate, , joinjoin, , inner_joininner_join, , left_outer_joinleft_outer_join,,

DBDB[[:tabel:tabel]...]...allall #records (Array of record) #records (Array of record)DBDB[[:tabel:tabel]...]...firstfirst #record (Hash of field_name / value) #record (Hash of field_name / value)DBDB[[:tabel:tabel]...]...order(order(:field:field))..lastlast #record #recordDBDB[[:tabel:tabel]...]...mapmap :field :field #Array of value#Array of value

DBDB[[:tabel:tabel]...[]...[Integer / HashInteger / Hash]]IntegerInteger=> ...=> ...limitlimit((IntegerInteger).).allallHashHash => ... => ...wherewhere((Hash Hash ).).firstfirst

DBDB[[:tabel:tabel]...[ ]...[ 22]] #eq #eq DBDB[[:tabel:tabel].].limitlimit( ( 22).).allallDBDB[[:tabel:tabel]...[]...[:id:id=>=>22]] #eq #eq DBDB[[:tabel:tabel].].wherewhere((:id:id=>=>22).).firstfirst

#Summarizing: result Number #Summarizing: result Number ......countcount, , maxmax, , minmin, , avgavg, , sumsum

#Manipulation #Manipulation DBDB[[:tabel:tabel]...]...deletedelete, ..., ...updateupdate, , insertinsert, , <<<<

Sequel – DB ToolkitSequel – DB Toolkit


Top Related