An open API service indexing awesome lists of open source software.

https://github.com/xwmx/parent_resources

DRYing Up Polymorphic Controllers
https://github.com/xwmx/parent_resources

Last synced: about 2 months ago
JSON representation

DRYing Up Polymorphic Controllers

Awesome Lists containing this project

README

          

h1. ParentResources

Simple parent object filter for polymorphic resource controllers. More info from "Val Aleksenko":http://revolutiononrails.blogspot.com/2007/05/drying-up-polymorphic-controllers.html and "Davis Cabral":http://daviscabral.com.br/articles/2008/5/25/polymorphic-resources-de-uma-forma-dry

h1. Example

Example controller:



class CommentsController < ApplicationController
parent_resources :article, :document

def new
@parent = parent_object
@comment = Comment.new
end

def create

@parent = parent_object
@comment = @parent.comments.build(params[:comment])

if @comment.valid? and @comment.save
redirect_to send("#{ parent_type }_url", @parent)
else
render :action => 'new'
end
end
end