Golden Retriever automatically retrieves resources from the database for
actions/controllers that follow rest conventions.
Instructions:
script/plugin git://github.com/DouglasMeyer/golden_retriever.git
And add "require GoldenRetriever" to the controllers for which you want your
resources automatically retrieved, and the resoures will be loaded under their
names. You can also define "resource_find_method" to specify a different find
method (like :find_by_name).
Example:
ActionController::Routing::Routes.draw do |map|
map.resources :users, :has_many => :posts
end
class PostsController < ApplicationController
require GoldenRetriever
# In this controller, you'll have access to @user, which is
# the same as: User.find(params[:user_id])
def index
# @posts will be the same as @user.posts
render :json => @posts
end
def show
# @post will be the same as @user.posts.find(params[:id])
render :json => @post
end
def new
# @post will be the same as @user.posts.build
render :json => @post
end
private
def resource_find_method(model_name)
model_name == 'post' ? :find_by_name : :find
end
end
Project
golden_retriever
Restful controllers will have their resources automatically loaded for them.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
Pull Requests
Development
Dependencies
Development
active_support
>= 2.3.0
>= 0
Project Readme