Inherited Resources Drying for Controller

Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important. It makes your controllers more powerful and cleaner at the same time.

Plus, making your controllers follow a pattern, it helps you to write better code by following fat models and skinny controllers convention. There are two screencasts available besides this README:

Installation in Rails 3

You can let bundler install Inherited Resources by adding this line to your application’s Gemfile:

gem 'inherited_resources'

And then execute:

bundle install

Or install it yourself as:

gem install inherited_resources

Basic Usage

To use Inherited Resources you just have to inherit (duh) it:

class ProjectsController < InheritedResources::Base

And all actions are defined and working, check it! Your projects collection (in the index action) is still available in the instance variable @projects and your project resource (all other actions) is available as @project.

The next step is to define which mime types this controller provides:

class ProjectsController < InheritedResources::Base
  respond_to :html, :xml, :json

About me
Interested about Ruby on Rails

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: