Simple Sinatra MVC Template
- PostgreSQL gem (pg)
- A lot more
$ git clone --depth 1 git://github.com/katgironpe/simple-sinatra-mvc.git myapp $ rm -r myapp/.git && rm myapp/README.md
Use bundler to install gems
$ bundle install
Start the app
$ shotgun config.ru
Unit and acceptance tests
Use RSpec for unit tests and functional tests.
$ rspec .
For acceptance tests, some example is also provided. Use:
Or use the rake task (
$ cp config/database.yml.example config/database.yml
By default, we use PostgreSQL.
To install PostgreSQL on a Mac, you might need homebrew.
$ brew install postgresql
Creating a database should be as simple as:
$ createdb database_name
You may have to update
config.ru and files on config directory as needed.
$ rake -T
rake assets:clean # Clean assets rake assets:precompile # Precompile assets rake db:create_migration # create an ActiveRecord migration rake db:migrate # migrate the database (use version with VERSION=n) rake db:rollback # roll back the migration (use steps with STEP=n) rake db:schema:dump # dump schema into file rake db:schema:load # load schema into database rake features # Run Cucumber features
To create a database for a specific environment, do:
$ rake db:create RACK_ENV=production
The default environment is "development"
To create a migration file called "create_pages", do:
$ rake db:create_migration NAME=create_pages
To do migration:
$ rake db:migrate RACK_ENV=production
$ rake db:rollback RACK_ENV=production
The default is development so this should just work:
$ rake db:migrate
To start the application, use
$ bundle exec shotgun config.ru
Yes, it is very easy to get asset pipeline working for Sinatra. By default, we have the following supported directories:
You may append more paths as needed by adding directory name to the
To precompile assets, simply use the rake task for it either on your deployment file or locally:
rake assets:precompile RACK_ENV=production
You have to use the asset helpers provided by
We use memcached to speed up loading of assets and storing them whether they're compressed or not. It is highly recommended to enable this by default in production.
To install memcached:
brew install memcached
I found a need to add this all the time. You will just need to download the