Model Loader

ModelLoader abstracts a common (at least for me) pattern in Rails applications. When creating controllers that interact with models it is common to have methods called find_<model_name> for your models. This module defines those find_* methods for you.

When executing the find_* methods, if a matching record can not be found, the user is redirected to the 404 page.

Installation

Include the gem using bundler in your Gemfile:

gem "model_loader"

Usage

The module is activated by calling the can_find_models method:

class ApplicationController < ActionController::Base
  can_find_models
end

Valid options are :only and :except:

class ApplicationController < ActionController
  can_find_models :only => 'Person'
end