A Model Only Server
JavaScript Ruby CoffeeScript Shell
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.


Amos - A Model Only Server.

AMOS is a rails plugin that provides a simple server that uses the url to decide which model to deliver. It is intended for front-end applications that use something like javascriptMVC.

E.g. If the incoming request is /recipe it executes the index action which does a find(:all) on the Recipe model.

Supported actions

:get => "/user" returns array of all users

:get => "/user?fields[only]=name" returns only the name attribute

:get => "/user?name=J%20Smith" returns all records with a name of J Smith

:get => "/user?name=J%20Smith&email=smith@smith.com" returns all records with a name of J Smith and an email of smith@smith.com

:get => "/users/1" returns record for user 1

:get => "/users/1?fields[only]=name" returns only the name attribute for user 1

:get => "/users/1?fields[include]=posts" returns the record for user plus any posts

:delete => "/users/1" deletes record 1 from users, returns success => true / false

:put => "/users/1" + form data. Updates user record 1.  Returns success => true / false

:post => "/users" + form data.  Create a new record, returns details of new record on success, or errors array on failure

*Amos gem is now available on rubygems.org*

Distributed under the MIT License, all rights reserved 2011 Geoff Drake


The source is available on GitHub github.com/geoffd123/amos


Create a rails application as normal using:

rails create MyApp

Add the following line to your Gemfile

gem 'amos'


bundle install

Amos uses cancan for its security checking so you need to add the following class in app/models/ability.rb

class Ability
  include CanCan::Ability

  def initialize(user)
    can :manage, :all

Replace the code inside the initialize with your requirements. There is a skeleton class in lib/app/models/ability.rb that disallows any access, so if you are getting authorisation errors you have not overridden that version correctly.

Cancan also needs access to a method called current_user in the controllers. If you are using devise or similar this should automatically be available.

If not you will need to define the following in your ApplicationController class:

class ApplicationController < ActionController::Base
  def current_user

If you are using user authentication replace the nil return with the current user record.

Finally create some models that match the code you have on the front-end.

rails g model recipes name:string description:string

And start the server

rails s

Your models should now be available on /recipe etc.

Take a look at spec/controllers/amos_controller_spec.rb and test/dummy/features/amos.feature for some examples of accessing the data and what is returned.

If you want to use pagination add limit=n and offset=n to your query url

:get => "/user?limit=10&offset=20" returns an array of the next 10 users starting at record 20

Things to to

  • More tests against a javascriptMVC application

Change list


Merged Nico's changes to make returned data more jsmvc compliant and the accessing more active record friendly. Thanks Nico.

Updated specs and cukes to test the above changes.

Updated README to conform to above changes.

Removed will_paginate gem as pagination is now controlled from the client.


Added test and spec files to gemspec

Added functionality to allow use of rails dynamic finders

Added ability to paginate index and dynamic finder results


Fixed problem with incomplete file list in gemspec.

Fixed problem with cancan methods not being found when using gem in a rails app.


Implemented fields filters, associations.

Changed js errors to return correct status codes

Implemented pluggable security using CanCan


Basic skeleton and minimal functionality