Ruby Sinatra
Rails is terrific, but if you're new to web development, I suggest you give Sinatra a try first. Not only is it excellent for building small web apps, but concepts such as routing are also much easier to understand and learn.
Sinatra Framework
Install Sinatra Framework
gem install sinatra
ORM
DataMapper is broken up into the core library, dm-core
, various database adapters and a number of optional libraries collectively:
- dm-core
- dm-aggregates
- dm-constraints
- dm-migrations
- dm-transactions
- dm-serializer
- dm-timestamps
- dm-validations
- dm-types
Install everything:
gem install data_mapper
Install things piece by piece:
DataMapper core
gem install dm-core
Constraints
require 'dm-constraints'
Migrations
require 'dm-migrations'
Pick a database adapter:
MySQL
gem install do_mysql
Postgresql
gem install do_postgres
SQLite
gem install dm-sqlite-adapter
Views
sudo gem install Haml
Example File
This file model.rb
starts with
require 'rubygems'
require 'dm-core'
#require 'dm-constraints'
require 'dm-migrations'
require 'sinatra'
require 'sinatra/reloader' if development?
DataMapper::Logger.new($stdout, :debug)
DataMapper.setup(:default, 'mysql://localhost/ruby_shortner')
Reloader
Reloader is great for restarting your computer every time you make a file edit.
gem install sinatra-contrib
Add this to index.rb
require 'sinatra'
require 'sinatra/reloader' if development?