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
- Host: GitHub
- URL: https://github.com/xwmx/parent_resources
- Owner: xwmx
- License: mit
- Created: 2008-10-05T22:24:23.000Z (about 17 years ago)
- Default Branch: master
- Last Pushed: 2008-10-06T17:27:24.000Z (about 17 years ago)
- Last Synced: 2025-05-08T18:50:54.473Z (5 months ago)
- Language: Ruby
- Homepage: http://revolutiononrails.blogspot.com/2007/05/drying-up-polymorphic-controllers.html
- Size: 85.9 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.textile
- License: MIT-LICENSE
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