recently got into ruby coding for a project at my day time job. my first impression while i was learning ruby to get started was.. its so simple and beautiful, yukihiro was certain right when he said programmer will enjoy coding in ruby, i certainly do enjoy coding in ruby. before getting into ruby, i coded in php and python, they certainly are pretty good languages but ruby is just different or in simple term "awesome".
thou the project i was working on does not have any web framework, project was more of coding standalone ruby scripts which does couple of web service call and render the html, it was fun period to learn and code.
i wanted to extend my skill to learn web framework and build same cool app with ruby. while googling about the ruby web framework.. obvious and the most worldly popular framework is the Rails. i want to learn rails but i wanted to start off with simple framework or micro framework, to get more handle on ruby coding.
google listed sinatra (micro framework), it is simple, easy and in real term small or micro framework as said over the web. in technical term sinatra is more of DSL (domain specific language). sinatra has really good documentation and is one of the best gem to start looking at while getting into the web development with ruby.
sinatra learning process was really amazing thanks to awesome ruby developer all over the world for building app and blogging about them. i have build medium and small application with sinatra, sinatra is always my first preference when ever i want to build out pet project or web services for mobile application.
getting started with sinatra can be as simple as requiring the gem in a rb file
1 2 3 4 5 6 7 | require 'sinatra' #install gem from terminal first get '/' do # method to handle the request "hello world" #response to request end |
note: do keep in mind to install sinatra gem with "gem install sinatra"
if you execute the script it will fire up the WEbrick web server servering the web pages at default port 4567.
since sinatra is DSL designed to work over web and HTTP, its method are named closely to relate http verbs like "GET", "POST", "PUT" , "DELETE".
here is my code for complete crud operation in sinatra, a simple disc listing system, to manage a huge collection of dvds i have from earlier days. created as simple model with couple of fields and how i arrange by the dvd disc in cases etc. UI is not fancy or smart, its pretty simple with angularjs, to have dynamic searching.
Github Link: https://github.com/zeet2020/simple-sinatra-app
do leave any comments or suggestion
Happy coding...