Skip to content

A simple concern that handles finding the model for a controller and creating a variable to hold it

Notifications You must be signed in to change notification settings

jolim/resource_concern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

resource_concern

Include this controller concern in a RESTful controller to automatically look up the object and store it in the variable named by the controller. It automatically applies to [:destroy, :edit, :show, :update].

If you want it to do the lookup for a different method, invoke get_resource in that method.

For example:

class PostController < ApplicationController
  include ResourceConcern

  def show
    # @post is automagically defined!
  end

  def author_view
    get_resource
    # @post is now defined
  end
end

The default resource class is the name of the controller. It throws away any namespace component.

If you want to specify a different resource class, use:

acts_as_resourceful klass: <Class::Name>

About

A simple concern that handles finding the model for a controller and creating a variable to hold it

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages