An easy way to add RESTful actions

Mongosteen is a library that helps to easily add RESTful actions to mongoid models, providing support for search, pagination, scopes, json configuration and history.

Mongosteen is based on inherited_resources gem, get yourself familiar with how it works and what you can do with this great tool.


  1. Add Mongosteen to your Gemfile:
  gem 'mongosteen'
  1. Create controller for the model (e.g. Post):
  class PostsController < ApplicationController
  1. Connect new controller in routes.rb:
  resources :posts

Mongosteen API


Index supports search, page, perPage and scope parameters:


Check out external gems documentation to see what options they provide:

  • mongoid_search — search for mongoid models;
  • kaminari — generic Rails pagination solution;
  • has_scope — easy way to access mongoid model scopes via controller;


Get specific resource version:


No how to add history support for mongoid model, check out:

JSON configuration for models

Sometimes there is a need to configure json output for the model, for example to add model method to output or exclude some internal fields. Mongosteen provides an easy and isolated way to do that in model controller using json_config method:

  class PostsController < ApplicationController
    json_config methods: %w(published_at)

json_config accepts configuration hash and passes it to as_json method while rendering document json.

If you need to define configuration specifically for methods, e.g. index might not need all document fields to make requests lighter, there is an actions special key for that:

class PostsController < ApplicationController
  json_config methods: %w(published_at),
              actions: {
                index: { methods: %w(published_at), exclude: %w(body_html) }

There are four default actions you can use here: index, show, create, update. Also you can specify your custom methods defined in controller and connected via routes.

Permitted Parameters

For rapid prototyping, Mongosteen allows all input parameters for create and update methods. This default behaviour can be overriden by using permitted_params method in controller, e.g:

  class Admin::PostsController < Admin::BaseController


      def post_params
        params.require(:post).permit(:title, :body)

Mongosteen family

  • Character: Powerful responsive javascript CMS for apps
  • Mongosteen: An easy way to add RESTful actions for Mongoid models
  • Inverter: An easy way to connect Rails templates content to Character CMS
  • Loft: Media assets manager for Character CMS


Copyright © 2015 Slate Studio, LLC. Mongoosteen is free software, and may be redistributed under the terms specified in the license.

About Slate Studio

Slate Studio

Mongoosteen is maintained and funded by Slate Studio, LLC. Tweet your questions or suggestions to @slatestudio and while you’re at it follow us too.