Skip to main content

Setting up Sinatra and DataMapper on Windows


I use a MacBook Pro for work and pleasure on a day-to-day basis. Recently, I was asked to teach web students at a local high school. These students know html/graphics/flash/etc. The advanced students were ready for some server-side programming and database integration. I wanted the students to be able to get up and going quickly (for motivation reasons) and to create useful apps (using a database). I felt Sinatra to be a great fit for this. I created a Sinatra app for my uncle and his business. It was a joy to work with it and I was able to deploy quickly using Heroku.
My experience of using Sinatra on my Mac was straightforward. Like most things using Ruby and Mac: it just worked. However, I found out the students at the high school use MS Windows. Fortunately, I have a Windows XP virtual machine running in VMWare so I could prepare that way. I used to teach computer science and web development at Spokane Community College and am aware of teaching Ruby in a Windows lab environment. Things can get tricky at times - and preparing a Sinatra app on Windows XP was a little tricky.
Here I am to quickly document what I can about setting up Sinatra on a Windows environment.

  1. Grab the installer and install Ruby: http://rubyinstaller.org/
  2. Install Sinatra from the Command Prompt:
    1. c:> gem install sinatra
  3. Install sqlite3
    1. Go to http://www.sqlite.org/download.html and download the Precompiled Binaries for Windows:
      1. sqlite-3.x.y.z.zip
      2. sqlitedll-3.x.y.z.zip
    2. Unzip and look for these files. Copy them into the Ruby bin directory path c:\ruby\bin
      1. sqlite3.exe
      2. sqlite3.dll
      3. sqlite3.def
    3. Install sqlite3-ruby gem
      1. c:> gem install sqlite3-ruby
  4. Install DataMapper
    1. c:> gem install dm-core
    2. c:> gem install do_sqlite3
  5. Code Reloading:
    1. Sinatra by default does not reload your code while you are editing and saving. Thus you have to restart sinatra server after changes = annoying!
    2. On the Mac I quickly found shotgun for my code reloading needs. However shotgun does not work on Windows. :(
    3. I then found out another gem that does code reloading on Windows: sinatra-reloader whew!
      1. c:> gem install sinatra-reloader
  6. Sinatra starter code:
    1. Put the code snippet (see below) into a file and save as: sinatra_starter.rb
    2. From command prompt, start the sinatra server:
      1. c:> ruby sinatra_starter.rb

I hope this helps get some of you started with Sinatra development on Windows. Please refer to these resources to further your Sinatra knowledge:


Comments

  1. Thanks Blake, Brandon here from the HS... Would you follow the same steps as that on a webserver if you were using ruby for a website?

    ReplyDelete
  2. Brandon, if you were setting up your own web server, yes you would follow these steps. Another option is to host your app on a web host like heroku. http://heroku.com

    ReplyDelete
  3. Hmmm Okay that looks good :D

    ReplyDelete
  4. Other options for reloading Sinatra apps on windows include using Rack::Reloader. I have also found that using JRuby Rack containers, like Trinidad to be really useful - fast, and you get source reloading for free without having to modify your code to take advantage of it.

    ReplyDelete
  5. richard, sweet! thanks for the suggestion.

    ReplyDelete

Post a Comment

Popular posts from this blog

Beginning Erlang for Ruby Developers

If you missed my "Beginning Erlang for Ruby Developers" here is a link to the presentation.

https://beg-erlang-for-ruby-devs.herokuapp.com/




Improving Traditional Software Development Education

I read Corey Haines post about his idea for software development school. I thought I'd jot down some of my experiences while I taught software development.
I taught community college computer science and web development for 7 years. In the summers I worked as a contractor to gain 'real-world' experience. This allowed me to teach what I learned over the summers in the classroom. Towards the last couple of years of teaching I worked at nights while I was teaching because I enjoyed it so much.
To me I saw a lot of teachers take the easy road: picking canned curriculum that laid out non-practical material, have a work study student grade for them, etc. while they go home early. This was frustrating to watch and be around!! I picked industry books (PragProg, Addison-Wesley, etc.) and used them for reference while I created custom curriculum every quarter because of technology changes. I did not picked canned textbooks. They drove me nuts being out of date and out of touch…