Skip to content

colszowka/activerecord-skeleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello, fellow traveler. This project is very outdated nowadays (Dec 2013). Please checkout https://github.com/colszowka/rack-boilerplate for a more current approach to this

ActiveRecord Skeleton

A basic skeleton for ActiveRecord-backed Ruby apps

http://blog.olszowka.de/2009/02/21/introducing-activerecord-skeleton/

Features

  • YAML database config
  • Rake tasks for generating migrations and migrating the database
  • Reasonable, Rails-style directory structure
  • Ready to go with SQLite 3
  • RACK_ENV-aware and thus ready to use with multiple environments with Sinatra or any other Rack-backed webapp framework
  • Logging for ActiveRecord

Setup

  1. Get and extract tarball or git clone this repository
  2. Copy config/database.sample.yml to config/database.yml
  3. Create a migration with rake generate:migration NAME=create_users and add your code in db/migrate/001_create_users.rb
  4. rake migrate (if you stick to the default SQLite setup, the database for the current environment will be automatically created upon migration)
  5. Create a model in lib/user.rb: class User < ActiveRecord::Base; end;
  6. Add application code in project root directory and require 'init' in it

Example for usage with Sinatra

In your application file (say app.rb sitting in the project root), simply add require 'init' after require 'sinatra'.

A basic sinatra app.rb might look like following (assuming you’ve got the user model setup and migrated)


require ‘sinatra’
require ‘init’

get ‘/’ do
User.all.map {|u| u.name}.to_sentence
end

Copyright

activerecord-skeleton is Copyright © 2009 Christoph Olszowka, It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.

About

A basic skeleton for ActiveRecord-backed Ruby apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages