Permalink
Browse files

cleaning up and documenting

git-svn-id: http://jnewland.com/svn/public/ruby/rails/plugins/resource_this@32 9b6b69f6-dd27-0410-8144-a0f3c56a22ea
  • Loading branch information...
jnewland
jnewland committed Sep 16, 2007
1 parent f7fdf74 commit 3d6c8922185dd7d5fe962cb88afd4d95eb6b406f
Showing with 106 additions and 7 deletions.
  1. +100 −1 README
  2. +6 −6 lib/resource_this.rb
View
101 README
@@ -1,6 +1,105 @@
resouce_this
===========
-docs here
+Not scaffolding. Resourcing. Creates extremely customizable resource controllers with one line of code.
+
+ class PostsController < ActionController::Base
+ resource_this
+ end
+
+...will generate the following code:
+
+ class PostsController < ActionController::Base
+ before_filter :load_post, :only => [ :show, :edit, :update, :destroy ]
+ before_filter :load_posts, :only => [ :index ]
+ before_filter :new_post, :only => [ :new ]
+ before_filter :create_post, :only => [ :create ]
+ before_filter :update_post, :only => [ :update ]
+ before_filter :destroy_post, :only => [ :destroy ]
+
+ protected
+ def load_post
+ @post = Post.find(params[:id])
+ end
+
+ def new_post
+ @post = Post.new
+ end
+
+ def create_post
+ @post = Post.new(params[:post])
+ @created = @post.save
+ end
+
+ def update_post
+ @updated = @post.update_attributes(params[:post])
+ end
+
+ def destroy_post
+ @post = @post.destroy
+ end
+
+ def load_posts
+ @posts = Post.find(:all)
+ end
+
+ public
+ def index
+ respond_to do |format|
+ format.html
+ format.xml { render :xml => @posts }
+ end
+ end
+
+ def show
+ respond_to do |format|
+ format.html
+ format.xml { render :xml => @post }
+ end
+ end
+
+ def new
+ respond_to do |format|
+ format.html { render :action => :edit }
+ format.xml { render :xml => @post }
+ end
+ end
+
+ def create
+ respond_to do |format|
+ if @created
+ flash[:notice] = 'Post was successfully created.'
+ format.html { redirect_to @post }
+ format.xml { render :xml => @post, :status => :created, :location => @post }
+ else
+ format.html { render :action => :new }
+ format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ respond_to do |format|
+ if @updated
+ flash[:notice] = 'Post was successfully updated.'
+ format.html { redirect_to @post }
+ format.xml { head :ok }
+ else
+ format.html { render :action => :edit }
+ format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ def destroy
+ respond_to do |format|
+ format.html { redirect_to :action => posts_url }
+ format.xml { head :ok }
+ end
+ end
+ end
Copyright (c) 2007 Jesse Newland, released under the MIT license
View
@@ -14,12 +14,12 @@ def resource_this(options = {})
will_paginate_index = options[:class_name] || false
module_eval <<-"end_eval", __FILE__, __LINE__
- before_filter :load_#{singular_name}, :only => [ :show, :edit, :update, :destroy ]
- before_filter :load_#{plural_name}, :only => [ :index ]
- before_filter :new_#{singular_name}, :only => [ :new ]
- before_filter :create_#{singular_name}, :only => [ :create ]
- before_filter :update_#{singular_name}, :only => [ :update ]
- before_filter :destroy_#{singular_name}, :only => [ :destroy ]
+ before_filter :load_#{singular_name}, :only => [ :show, :edit, :update, :destroy ]
+ before_filter :load_#{plural_name}, :only => [ :index ]
+ before_filter :new_#{singular_name}, :only => [ :new ]
+ before_filter :create_#{singular_name}, :only => [ :create ]
+ before_filter :update_#{singular_name}, :only => [ :update ]
+ before_filter :destroy_#{singular_name}, :only => [ :destroy ]
protected
def load_#{singular_name}

0 comments on commit 3d6c892

Please sign in to comment.