On Github nikhilbhardwaj / sinatra-class
I'm Nikhil Bhardwaj, a final year M.C.A. student here at NIT Trichy. I'm also the Projects Manager for Spider.
Facebok : bhardwaj.nikhil
Twitter : nik__bhardwaj
Email : root@nikhilbhardwaj.in
At the end of this class, you won't become a web development Ninja or know sinatra inside out. You will however get an idea of how simple web applications are built and hopefully you'll be motivated enough to give it a shot.
Becoming an expert needs practice, practice and yet more practice.
Removes the need for un-necessary protocols like soap which serve no purpose other than facilitating data exchange. Focusses on vocabulary re-use instead of arbitrary extension.
gem install sinatra
Create basics.rb
require 'sinatra'
Lets Run it!
get '/' do "Hello, World!" end
get '/about' do 'A little about me.' end
get "/reverse/:string" do params[:string].reverse end
get '/hello/:name/:city' do "Hey there #{params[:name]} from #{params[:city]}." end
get '/more/*' do params[:splat] end
Useful When dealing with unknow number of parameters.
Templates give us the ability to apply consistent styles to our websites. Also we don't just return strings to the browser, we need formatted html.
Some of the common templating engines supported by sinatra are:
mkdir views touch about.erb <h2><%= @about %></h2>
Add this to the /about section to
get '/about' do @about = 'Get to know a little about me.' erb :about end
I have already written the layout.erb, which is inherited by all other routes and your header, footer and the site markup go here.
get "/greet" do erb :form end post "/greet" do "You said #{params[:message]}" end
Any Doubts so far?
Heroku is the leading open language cloud application platform and supports Ruby, Java, Python, Clojure, Scala, Node.js.
heroku create git push heroku master
Gives you a link like http://floating-shore-4207.herokuapp.com/
What we've seen today is just the tip of the iceberg. There's a lot more to web development. Those of you who haven't developed a website previously should realize that this stuff is really easy. Trust me, it's a lot of fun when your first website is deployed on the internet.