rails / scaffolding

Dynamic Scaffolding plugin

This URL has Read+Write access

scaffolding / README
100644 74 lines (57 sloc) 2.212 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Scaffolding
===========
 
Scaffolding is a way to quickly put an Active Record class online by providing a series of standardized actions for listing, showing, creating, updating, and destroying objects of the class. These standardized actions come with both controller logic and default templates that through introspection already know which fields to display and which input types to use. Example:
 
The render_scaffold method will first check to see if you've made your own template (like "weblog/show.erb" for the show action) and if not, then render the generic template for that action. This gives you the possibility of using the scaffold while you're building your specific application. Start out with a totally generic setup, then replace one template and one action at a time while relying on the rest of the scaffolded templates and actions.
 
Example
=======
 
 class WeblogController < ActionController::Base
   scaffold :entry
 end
 
This tiny piece of code will add all of the following methods to the controller:
 
 class WeblogController < ActionController::Base
   verify :method => :post, :only => [ :destroy, :create, :update ],
          :redirect_to => { :action => :list }
 
   def index
     list
   end
 
   def list
     @entries = Entry.find(:all)
     render_scaffold "list"
   end
 
   def show
     @entry = Entry.find(params[:id])
     render_scaffold
   end
 
   def destroy
     Entry.find(params[:id]).destroy
     redirect_to :action => "list"
   end
 
   def new
     @entry = Entry.new
     render_scaffold
   end
 
   def create
     @entry = Entry.new(params[:entry])
     if @entry.save
       flash[:notice] = "Entry was successfully created"
       redirect_to :action => "list"
     else
       render_scaffold('new')
     end
   end
 
   def edit
     @entry = Entry.find(params[:id])
     render_scaffold
   end
 
   def update
     @entry = Entry.find(params[:id])
     @entry.attributes = params[:entry]
 
     if @entry.save
       flash[:notice] = "Entry was successfully updated"
       redirect_to :action => "show", :id => @entry
     else
       render_scaffold('edit')
     end
   end
 end
 
 
Copyright (c) 2004-2007 David Heinemeier Hansson, released under the MIT license