An ORM/MVC for Ruby, inspired by Ruby on Rails
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


ModelFrames is a basic ORM (Object Relational Management) / MVC (Model View Controller) framework written in Ruby and inspired by Ruby on Rails. ModelObject provides the ORM functionality, FramesController provides a base controller class, and Router provides basic routing capabilities.


Key Features

Custom classes that extend ModelObject inherit a number of ORM features:

  • parameters can be passed in a params hash (e.g. gerbil = 'Buki', color: 'striped', sound: 'squeak')). The keys must correspond to columns in the corresponding database table. By default, the table name is created by applying the ActiveSupport::Inflector::tableize method to the class name.
  • the ModelObject#save method will intelligently insert or update the related row in the database based on whether or not the id primary key is defined.
  • the ModelObject#destroy method will delete the related row from the database.
  • By calling self.finalize! at the end of your custom class definition, attribute accessors are created which correspond to the columns in the associated database table.

Example Usage

In the example application, gerbil.rb is located in the app/models folder:

require_relative '../../lib/model/model_object'

class Gerbil < ModelObject
  # no custom methods


Key Features

Custom classes that extend FramesController can use the following methods:

  • render(template_name): Render a template located in the app/views/<controller_name> directory.
  • render_content(content, content_type): Render custom content with the specified content_type.
  • redirect_to(url): Redirect to the passed URL.
  • session: key/value pairs saved to this hash are saved as cookies.
  • flash and key/values pairs saved to this hash will persist through the next session and the current session only, respectively.
  • By adding protect_from_forgery to your custom controller, Frames will check for an authenticity token in any submitted data. This token can be added to the forms in your views as follows:
  value="<%= form_authenticity_token %>" />

Example Usage

In the example application, gerbils_controller.rb is located in the app/controllers folder:

require_relative '../../lib/frames/frames_controller'
require_relative '../models/gerbil'

class GerbilsController < FramesController


  def new
    render :new

  def create
    @gerbil =
      name: params['gerbil']['name'],
      color: params['gerbil']['color'],
      sound: params['gerbil']['sound']
    redirect_to "/gerbils/#{}"




The Router allows the mapping of routes to your custom controllers. For example:

require_relative '../lib/frames/router'

router =
router.draw do
  get"^/gerbils/new$"), GerbilsController, :new
  post"^/gerbils$"), GerbilsController, :create
  get"^/gerbils/(?<gerbil_id>\\d+)$"), GerbilsController, :show
         GerbilsController, :destroy
  get"^/$"), GerbilsController, :index

Configuring Database Access

ModelObject uses a DBConnection class which works with SQLite. In the example app, this is configured in app/db.rb as follows:

require_relative '../lib/model/db_connection'

DBConnection.reset('gerbils.sql') unless DBConnection.db_file_exists?

You will need to create a .sql file to define the database structure (at minimum, though seeds can also be included). DBConnection will look for the file name passed to DBConnection.reset in the /db folder.

This configuration file should then be included in all your ModelObject subclasses.

Additional Rack Middleware

  • Exceptions provides a detailed error message for any Ruby errors, which is useful for development enviroments.

  • StaticAssets allows the serving of static assets from the /public folder. Currently supported extensions are .jpg, .png, .gif, and .htm/.html. All other extensions are served as plain text.

Putting it All Together

See app/gerbilville.rb for an example application entry file.

Running the Example App


Up-to-date versions of Ruby and Bundler

  1. git clone
  2. cd model-frames
  3. bundle install
  4. ruby app/gerbilville.rb
  5. Visit http://localhost:3000

Ideas for Future Enhancement

  • Create a CLI using Thor.
  • Package ModelFrames as a gem.