SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
SInatra?
SInatra?
Sinatra?
• Ruby製     
Webフレームワーク
• MCモデル
• お手軽
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?
• 本棚アプリ…

Contenu connexe

Tendances (8)

Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Sinatra Rack And Middleware
Sinatra Rack And MiddlewareSinatra Rack And Middleware
Sinatra Rack And Middleware
 
All About Sammy
All About SammyAll About Sammy
All About Sammy
 
Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013
 
Padrino is agnostic
Padrino is agnosticPadrino is agnostic
Padrino is agnostic
 
Your JavaScript Library
Your JavaScript LibraryYour JavaScript Library
Your JavaScript Library
 
Sphinx on Rails
Sphinx on RailsSphinx on Rails
Sphinx on Rails
 
Scalar::Footnote
Scalar::FootnoteScalar::Footnote
Scalar::Footnote
 

En vedette

Dominando dynos en heroku
Dominando dynos en herokuDominando dynos en heroku
Dominando dynos en heroku
fedesoria
 
実践プログラミング DSL
実践プログラミング DSL実践プログラミング DSL
実践プログラミング DSL
Nemoto Yusuke
 

En vedette (16)

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

Similaire à Sinatra slideshare

Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
Bryce Kerley
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
taggg
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
railsconf
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
Hugo Hamon
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
Jeremy Kendall
 

Similaire à Sinatra slideshare (20)

SINATRA + HAML + TWITTER
SINATRA + HAML + TWITTERSINATRA + HAML + TWITTER
SINATRA + HAML + TWITTER
 
Sinatra for REST services
Sinatra for REST servicesSinatra for REST services
Sinatra for REST services
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
Advanced Technology for Web Application Design
Advanced Technology for Web Application DesignAdvanced Technology for Web Application Design
Advanced Technology for Web Application Design
 
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Go Web Development
Go Web DevelopmentGo Web Development
Go Web Development
 
TDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em RubyTDC 2012 - Patterns e Anti-Patterns em Ruby
TDC 2012 - Patterns e Anti-Patterns em Ruby
 
Mojolicious, real-time web framework
Mojolicious, real-time web frameworkMojolicious, real-time web framework
Mojolicious, real-time web framework
 
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
 
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
Strangers In The Night: Ruby, Rack y Sinatra - Herramientas potentes para con...
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
Flex With Rubyamf
Flex With RubyamfFlex With Rubyamf
Flex With Rubyamf
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Leave end-to-end testing to Capybara
Leave end-to-end testing to CapybaraLeave end-to-end testing to Capybara
Leave end-to-end testing to Capybara
 
Speed up your developments with Symfony2
Speed up your developments with Symfony2Speed up your developments with Symfony2
Speed up your developments with Symfony2
 
HTML5 & Friends
HTML5 & FriendsHTML5 & Friends
HTML5 & Friends
 
Sinatra
SinatraSinatra
Sinatra
 
Leveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHPLeveraging the Power of Graph Databases in PHP
Leveraging the Power of Graph Databases in PHP
 

Dernier

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Dernier (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 

Sinatra slideshare