SlideShare a Scribd company logo
Sinatra slideshare
SInatra?
SInatra?
Sinatra?
• Ruby製     
Webフレームワーク
• MCモデル
• お手軽
Sinatra slideshare
Agenda
• Hello Sinatra
• View (Haml)
• DB(Active Record)
Hello World!
# coding: utf-8
require ‘sinatra’
get ‘/’ do
‘Hello Sinatra!’
end
sinatra.rb
http://0.0.0.0:4567/
COMMAND
ruby sinatra.rb
環境作り gem install sinatra
VIEW / Template
• Erb
• Haml
• Markdown
• 鋸
など
haml
• HTML abstraction markup language
• Haml accelerates and simplifies
template creation down to veritable
haiku
HAML
%html
%head
%title
Haml Sample
%body
Hello Haml!
<html>
<head>
<title>
Haml Sample
</title>
</head>
<body>
Hello Haml!
</body>
</html>
Sinatra with haml
http://twitter.github.io/bootstrap/
https://github.com/kaakaa/SinatraBenkyou1
#coding: utf-8
require 'sinatra'
require 'haml'
get '/' do
redirect '/Sinatra/'
end
get '/:name/' do
@display_name = params[:name]
haml :index
end
post '/hello' do
@name = params[:name]
if @name.nil? then
@name = "Sinatra"
end
redirect '/' + @name + '/'
end
sinatra.rb
%html
%head
%title
Haml Sample
%meta{ :charset => "utf-8" }
%script{ :src => "/js/jquery-1.9.0.min.js" }
%link{ :rel => "stylesheet", :href => "/css/bootstrap.css" }
%body
%div.input-append
%h3
INPUT YOUT NAME!
%form{ :method => "post", :action => "/hello" }
%input{ :type => "text", :name => "name",
:class => "span2" }
%input{ :type => "submit", :value => "SEND",
:class => "btn btn-small" }
%h2
= "Hello " + @display_name.to_s + " !"
index.haml
%html
%head
%title
Haml Sample
%meta{ :charset => "utf-8" }
%script{ :src => "/js/jquery-1.9.0.min.js" }
%link{ :rel => "stylesheet", :href => "/css/bootstrap.css" }
%body
%div.input-append
%h3
INPUT YOUT NAME!
%form{ :method => "post", :action => "/hello" }
%input{ :type => "text", :name => "name",
:class => "span2" }
%input{ :type => "submit", :value => "SEND",
:class => "btn btn-small" }
%h2
= "Hello " + @display_name.to_s + " !"
index.haml
%form{ :method => "post", :action => "/hello" }
%input{ :type => "text", :name => "name",
:class => "span2" }
%input{ :type => "submit", :value => "SEND",
:class => "btn btn-small" }
post '/hello' do
@name = params[:name]
if @name.nil? then
@name = "Sinatra"
end
redirect '/' + @name + '/'
end
Active Record Design Pattern
O/R Mapper
1Record = 1Object
https://github.com/kaakaa/Sinatra-Benkyou2
history Record
name
date_time
require 'active_record'
ActiveRecord::Base.configurations = YAML.load_file('database.yml')
ActiveRecord::Base.establish_connection('development')
class History < ActiveRecord::Base
end
development:
adapter: sqlite3
database: db/benkyo.db
sinatra.rb(partially)
database.yml
require 'active_record'
ActiveRecord::Base.configurations = YAML.load_file('database.yml')
ActiveRecord::Base.establish_connection('development')
class History < ActiveRecord::Base
end
development:
adapter: sqlite3
database: db/benkyo.db
sinatra.rb(partially)
database.yml
history
name
date_time
require 'active_record'
ActiveRecord::Base.configurations = YAML.load_file('database.yml')
ActiveRecord::Base.establish_connection('development')
class History < ActiveRecord::Base
end
development:
adapter: sqlite3
database: db/benkyo.db
history = History.new
history.name = @name
history.date_time = @date_time
history.save
history = History.find(‘2013/05/14 00:00:00’)
history.destroy
History.destroy_all
sinatra.rb(partially)
get '/' do
redirect '/Sinatra/'
end
get '/:name/' do
@display_name = params[:name]
@histories = History.all
haml :index
end
%h3
HISTORY
-@histories.each do |history|
%div
= history.date_time
= history.name
sinatra.rb(partially) index.haml(partially)
post '/*/hello' do
@name = params[:name]
if @name.nil? then
@name = "Sinatra"
end
day = Time.now
date_time =
day.strftime("%Y/%m/%d %H:%M:%S")
history = History.new
history.name = @name
history.date_time = @date_time
history.save
redirect '/' + @name + '/'
sinatra.rb(partially)
summary
• Hello Sinatra
• 簡単
• View (Haml)
• 楽
• DB(Active Record)
• 楽
summary
怠惰
bundle
source "https://rubygems.org"
ruby '2.0.0'
group :development, :test do
gem "sqlite3", '1.3.7'
gem "dm-sqlite-adapter"
end
gem "activerecord"
gem "sinatra",
git: 'https://github.com/juanpastas/sinatra.git'
gem "haml"
bundle install --path vendor/bundle
bundle exec ruby sinatra.rb
Gemfile
感想
感想
• Ruby周りは楽
• ただ、楽過ぎて怖い
• テスト環境ならOK?
• 本棚アプリ…

More Related Content

PDF
Web Development with Sinatra
PDF
Extracting ruby gem
KEY
DBIx::Skinnyと仲間たち
PPTX
Sinatra
PDF
HappyKardashian.com for #FVCP
PDF
Lightweight Webservices with Sinatra and RestClient
PDF
Using Sinatra to Build REST APIs in Ruby
PDF
CocoaPods Basic Usage
Web Development with Sinatra
Extracting ruby gem
DBIx::Skinnyと仲間たち
Sinatra
HappyKardashian.com for #FVCP
Lightweight Webservices with Sinatra and RestClient
Using Sinatra to Build REST APIs in Ruby
CocoaPods Basic Usage

What's hot (8)

PDF
Ruby on Rails - Introduction
PDF
Sinatra Rack And Middleware
KEY
All About Sammy
PDF
Ecossistema Ruby - versão SCTI UNF 2013
PDF
Padrino is agnostic
PDF
Your JavaScript Library
ZIP
Sphinx on Rails
PPT
Scalar::Footnote
Ruby on Rails - Introduction
Sinatra Rack And Middleware
All About Sammy
Ecossistema Ruby - versão SCTI UNF 2013
Padrino is agnostic
Your JavaScript Library
Sphinx on Rails
Scalar::Footnote
Ad

Viewers also liked (16)

PDF
Un newbie conoce a Sinatra
PPT
Dominando dynos en heroku
PPTX
Ruby 101 session 5
PDF
社内勉強会 - chef
PDF
社内勉強会 - 書籍管理Webシステム
PDF
SVG事始め
PDF
Scalaを触ってみた
PDF
実践プログラミング DSL
PDF
ブログる
PDF
Introducción a Ruby on rails
ODP
¿Por qué ruby on rails?
PDF
Gradle布教活動
PDF
10 cosas de rails que deberías saber
PDF
Gradle handson
PDF
Ruby on Rails Presentation
PDF
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Un newbie conoce a Sinatra
Dominando dynos en heroku
Ruby 101 session 5
社内勉強会 - chef
社内勉強会 - 書籍管理Webシステム
SVG事始め
Scalaを触ってみた
実践プログラミング DSL
ブログる
Introducción a Ruby on rails
¿Por qué ruby on rails?
Gradle布教活動
10 cosas de rails que deberías saber
Gradle handson
Ruby on Rails Presentation
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Ad

Similar to Sinatra slideshare (20)

KEY
Sinatra事始め
PDF
Ruby on Rails at PROMPT ISEL '11
PDF
Story for a Ruby on Rails Single Engineer
PDF
Ruby on Rails : 簡介與入門
PDF
Connecting the Worlds of Java and Ruby with JRuby
PDF
When To Use Ruby On Rails
PDF
Rails 2.3 and Rack - NHRuby Feb 2009
KEY
Ruby/Rails
PDF
OSDC 2009 Rails Turtorial
PDF
RubyOnRails-Cheatsheet-BlaineKendall
PDF
RubyOnRails-Cheatsheet-BlaineKendall
KEY
Intro to Ruby on Rails
PDF
浜松Rails3道場 其の四 View編
PDF
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
PDF
Sinatra and friends
PPTX
Learning to code for startup mvp session 3
PDF
Play vs Rails
PDF
浜松Rails3道場 其の弐 Model編
KEY
Rails Routing and URL design
PDF
Survey of Front End Topics in Rails
Sinatra事始め
Ruby on Rails at PROMPT ISEL '11
Story for a Ruby on Rails Single Engineer
Ruby on Rails : 簡介與入門
Connecting the Worlds of Java and Ruby with JRuby
When To Use Ruby On Rails
Rails 2.3 and Rack - NHRuby Feb 2009
Ruby/Rails
OSDC 2009 Rails Turtorial
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
Intro to Ruby on Rails
浜松Rails3道場 其の四 View編
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
Sinatra and friends
Learning to code for startup mvp session 3
Play vs Rails
浜松Rails3道場 其の弐 Model編
Rails Routing and URL design
Survey of Front End Topics in Rails

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
cuic standard and advanced reporting.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
KodekX | Application Modernization Development
PPT
Teaching material agriculture food technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Programs and apps: productivity, graphics, security and other tools
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Approach and Philosophy of On baking technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
Reach Out and Touch Someone: Haptics and Empathic Computing
cuic standard and advanced reporting.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
KodekX | Application Modernization Development
Teaching material agriculture food technology
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Sinatra slideshare