• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Sinatra
 

Sinatra

on

  • 1,654 views

Introduction to Sinatra

Introduction to Sinatra

Statistics

Views

Total Views
1,654
Views on SlideShare
975
Embed Views
679

Actions

Likes
0
Downloads
4
Comments
0

9 Embeds 679

http://8raystech.com 518
http://localhost 98
http://staging.8raystech.com 23
http://www.linkedin.com 20
http://www.8raystech.com 15
https://www.linkedin.com 2
https://si0.twimg.com 1
http://cloud.feedly.com 1
http://50.57.147.158 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Rake is a generic ruby library for building web applicationsRail3 has featured support for sinatra web applications

Sinatra Sinatra Presentation Transcript

  • SINATRANitesh KumarMember of technical staff11.12.12
  • ROADMAP What is sinatra? Why sinatra? Flexibility with sinatra Singing with sinatra File hierarchy and naming convention Features Sinatra with ActiveRecord
  • WHAT IS SINATRA?  A micro-framework for web applications  A ruby domain specific language  A ruby “gem”
  • WHY SINATRA?  Lightweight  Nicely pluggable within other application  Good tool for creating REST-like interface  Support many different template syntaxes.
  • SINATRA ON RAILS#in routes.rbmatch “/blog” => MySinatraBlogApp, :anchor => false#Sinatra appClass MySinatraBlogApp < Sinatra::Base #this now will match /blog/archives get “/archives” do “My old posts” endend
  • FLEXIBILITY WITH SINATRA :  Template engine  ERB, HAML, Builder..  ORM  ActiveRecord, DataMapper, Sequel  JS library  jQuery, Prototype, YUI, Dojo  Testing tool  Test::unit, Rspec, Bacon
  • LET‟S START THE SHOW  gem install sinatra  ruby hello-world.rb
  • SINGING WITH “SINATRA”#sample.rbrequire „rubygems‟require „sinatra‟get „ / ‟ do “Why this kolavari kolavari kolavari di..”end
  • SO Every url you wants to respond to goes in your .rb file Pages themselves goes in /views as .erb files Wrapping layout goes in /views/layout.erb Static files goes in public |-- beta.rb |--public | `--stylesheets | `--shared.css `-- views |--index.erb |--layout.erb
  • FEATURES: [ ROUTING ] Routing to code blockget „ / „ do “Hello world!” “ block ”end Whatever is returned from the block is sent to the browser
  • FEATURES: [ VIEWS ]#beta.rbrequire „rubygems‟require „sinatra‟get „ / ‟ do erb: indexend#views/index.erb<h3> Welcome the my website </h3><p>I‟m being developed . Thanks for stopping by.</p>
  • FEATURES: [ LAYOUTS ]#views/layout.rb<!DOCTYPE html><html> <head> <title>Beta Info</title> </head> <body> <%= yield %> </body></html>#views/index.erb<h3> Welcome the my website </h3><p>I‟m being developed . Thanks for stopping by.</p>
  • FEATURES: [FILTERS]beforebefore do MyStore.connect unless MyStore.connected?endget / do @list = MyStore.find(:all) erb :indexendafterafter do MyStore.disconnectend
  • FEATURES: [HELPERS]helpers do def bar(name) "#{name}bar“ endendget /:name do bar(params[:name])end
  • DYNAMIC URLS?#dynamic.rbrequire „rubygems‟require „sinatra‟get „ / ‟ do “This is homepage.”endget „/:name‟ do „Hello‟ + params[:name] + „!‟end
  • SINATRA WITH ACTIVERECORDrequire „rubygems‟require „sinatra‟require „active_record‟class Article < ActiveRecord::Baseendget „ / ‟ do Article.establish_connection( :adapter => “sqlite3”, :database => “hw.db” ) Article.first.titleend
  • REFERENCES http://sinatra-book.gittr.com/ http://www.sinatrarb.com/ http://www.slideshare.net/Cannikin/classy-web- development-with-ruby-sinatra-and-heroku-1
  • THANKS!