Enhances Rails with default REST functionality.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Gem Version Code Climate GPA Code Climate Coverage Gemnasium Status Travis CI Status Patreon

Enables default REST functionality, more than what you get with Rails out-of-the-box, which keeps your code DRY. This means you can write code like this:

class Posts < ApplicationController

Which would automatically add the following REST actions to your controller:

  • index
  • show
  • new
  • edit
  • create
  • update
  • destroy

Table of Contents


Supports the following gems (if detected):

Supports the following JavaScript libraries:


  1. Ruby 2.x.x.
  2. Ruby on Rails 5.x.x.
  3. Knowledge of Representational State Transfer (REST).


For a secure install, type the following from the command line (recommended):

gem cert --add <(curl --location --silent https://www.alchemists.io/gem-public.pem)
gem install resourcer --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

gem install resourcer

Add the following to your Gemfile file:

gem "resourcer"

Add the following to your application.js file:

//= require jquery.rest

For first time installers, run the install generator:

rails generate resourcer:install

For upgrades to previous releases, run the upgrade generator:

rails generate resourcer:upgrade


Add the resourcer macro to your controllers to make them RESTful. For example:

class Posts < ApplicationController

This will automatically add the seven REST actions (index, show, new, create, edit, update, and destroy) to your controller. The model class and instance names are automatically determined from the controller name. To further customize the behavior of the resourcer macro, the following options are available:

  • *label- - Optional. The resource label. Defaults to the controller name with capitalization. Example: posts => Posts.
  • *belongs_to- - Optional. The parent symbol (including namespaces delimited by underscores). Example: Public::PostsController, Result: :public_posts. Defaults to nil.
  • *parent_key- - Optional. The ID key of the parent resource (for nested resources only). Defaults to _id
  • *parent_value- - Optional. The ID value of the parent resource (for nested resources only). Defaults to the record id.
  • *parent_resource_method- - Optional. The instance method to call for acquiring child resource(s) of the parent (for nested resources only). Example: A post with many comments would be post.comments. Defaults to child resource name.
  • *controller_class- - Optional. The controller class (for nested resources only). Defaults to the current class. You should never need to use this.
  • *controller_name- - Optional. The controller name. Defaults to the controller class name minus the "Controller" suffix (same behavior as used in routing). Example: PostsController => posts
  • *model_class- - Optional. The model class. Defaults to the same name as the controller (minus namespace, suffix, and pluralization of course). Example: PostsController => Post
  • *model_name- - Optional. The model name. Defaults to the singularized version of the :controller_name. Example: posts (controller_name) => post (model_name).
  • *model_object- - Optional. The model object. The name defaults to the model_name. Example: post (model_name) => @post (model object). You should never need to use this but, hey, better safe than sorry.
  • *model_find_method- - Optional. The method used to find a model object. Defaults to :find.
  • *namespaces- - Optional. The namespaces (if any) for routing. Defaults to the controller namespace.
  • *index_template- - Optional. The index template. Defaults to "///index".
  • *show_template- - Optional. The show template. Defaults to "///show".
  • *new_or_edit_template- - Optional. The new or edit template. Defaults to "///new_or_edit".
  • *authorize- - Optional. Boolean. Authorizes the resource via the CanCan gem. Defaults to true.
  • *disabled_actions- - Optional. An array of REST actions to disable. Defaults to [].

Your view templates can be written as follows (Note: the new and edit actions share the same view):


      <th>Created At</th>
      <th>Updated At</th>
    <%= render @posts %>


<p><%= @post.label %></p>

<p><%= @post.content %></p>


<% form_for @post do |form| %>
  <%= render "shared/error_messages", target: @post %>

   <%= form.label :label %><br/>
   <%= form.text_field :label %>

   <%= form.label :content %><br/>
   <%= form.text_area :content %>

  <div><%= submit_tag "Save", class: "form-button" %></div>
<% end %>

Finally, don't forget to update your routes when making your controllers resourceful. When using the example above, the following would be added to your routes file:

map.resources :posts


To learn more about REST in Rails, check out the following:

  • RESTful Rails - A PDF work downloading and reading that inspired me to write this gem.
  • Rails Routing - The definitive guide to RESTful routing in Rails.
  • Taking Things Too Far - A good read on knowing when you have gone too far with the REST API.


To test, run:

bundle exec rake


Read Semantic Versioning for details. Briefly, it means:

  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible, public API enhancements/fixes.
  • Patch (x.y.Z) - Incremented for small, backwards compatible, bug fixes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.


Read CONTRIBUTING for details.


Copyright (c) 2010 Alchemists. Read LICENSE for details.


Read CHANGES for details. Built with Gemsmith.


Developed by Brooke Kuhlmann at Alchemists.