trestle_generator 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +129 -0
- data/templates/routes.rb +6 -6
- metadata +5 -12
data/README
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
================================================================================
|
2
|
+
Trestle Generator
|
3
|
+
================================================================================
|
4
|
+
|
5
|
+
A drop-in replacement for Ruby on Rails�s scaffold generator
|
6
|
+
|
7
|
+
Everybody loves scaffolding, and with good reason. It�s the feature of the Ruby
|
8
|
+
on Rails framework that makes a database table editable on the web in mere
|
9
|
+
seconds, and with just a few lines of generated Ruby code.
|
10
|
+
|
11
|
+
The trestle generator is drop-in replacement for the Rails scaffold generator.
|
12
|
+
It produces scaffolding that�s more like production-quality code while
|
13
|
+
maintaining all the rapid goodness you know and love about Rails.
|
14
|
+
|
15
|
+
Don�t drive your train across a gorge with nothing but a scaffold underneath it.
|
16
|
+
Use a trestle instead!
|
17
|
+
|
18
|
+
Trestles have two advantages over scaffolds:
|
19
|
+
|
20
|
+
* More elegant handling of HTTP POST and GET requests
|
21
|
+
* A streamlined URL structure that makes your application easier to use
|
22
|
+
|
23
|
+
Downloading and installation is a breeze with RubyGems, the package manager
|
24
|
+
that�s included in most Ruby distributions. Just type the following at a command
|
25
|
+
line:
|
26
|
+
|
27
|
+
gem install trestle_generator
|
28
|
+
|
29
|
+
Generating trestles for your database tables is also a one-step process:
|
30
|
+
|
31
|
+
script/generate trestle YourModelNameHere
|
32
|
+
|
33
|
+
--------------------------------------------------------------------------------
|
34
|
+
Why switch from scaffolds to trestles? SAFETY
|
35
|
+
--------------------------------------------------------------------------------
|
36
|
+
|
37
|
+
The trestle generator produces Rails views that use HTTP POST to request changes
|
38
|
+
(instead of GET). It also generates Rails controllers that execute such changes
|
39
|
+
only for HTTP POST requests. Well-behaved web applications must protect user
|
40
|
+
data against unwanted changes, including those arising from errant HTTP GET
|
41
|
+
requests such as Google Web Accelerator is known to make. The scaffolding
|
42
|
+
provided by Rails v1.1 is better about this than Rails v1.0 was, but trestles
|
43
|
+
solve the problem of GET vs POST more cleanly and comprehensively.
|
44
|
+
|
45
|
+
--------------------------------------------------------------------------------
|
46
|
+
Why switch from scaffolds to trestles? USABILITY
|
47
|
+
--------------------------------------------------------------------------------
|
48
|
+
|
49
|
+
Trestle controllers have just four actions (index, new, edit, and destroy).
|
50
|
+
Contrast this with scaffold controllers which have eight actions to implement
|
51
|
+
the same functionality. This is mostly a matter of taste, but Rails developers
|
52
|
+
appreciate more than most that �less is more.�
|
53
|
+
|
54
|
+
Just as important as aesthetics is the fact that trestle controllers better
|
55
|
+
reflect GET and POST semantics, making for more intelligible HTTP conversations
|
56
|
+
in your applications. (Apparently, Tobias L�tke wrote a postback_generator
|
57
|
+
RubyGem with a similar philosophy, but trestles take the concept further.)
|
58
|
+
|
59
|
+
Use trestles instead of scaffolding and you will find yourself throwing away and
|
60
|
+
tweaking less code as you build out applications. As joyous as Ruby programming
|
61
|
+
is, less code is still a good thing.
|
62
|
+
|
63
|
+
Let�s look at some of the differences between trestles and scaffolds. A scaffold
|
64
|
+
for a database table named �people� has the following HTTP interface:
|
65
|
+
|
66
|
+
URL Result
|
67
|
+
================================================================================
|
68
|
+
/people Lists existing person records
|
69
|
+
/people/list
|
70
|
+
--------------------------------------------------------------------------------
|
71
|
+
/people/new Shows an empty person form
|
72
|
+
--------------------------------------------------------------------------------
|
73
|
+
/people/create Creates a new person record from request parameters
|
74
|
+
--------------------------------------------------------------------------------
|
75
|
+
/people/show/99 Shows the person record having ID 99
|
76
|
+
--------------------------------------------------------------------------------
|
77
|
+
/people/edit/99 Shows a person form for the person record having ID 99
|
78
|
+
--------------------------------------------------------------------------------
|
79
|
+
/people/update/99 Updates the person record having ID 99 using request
|
80
|
+
parameters
|
81
|
+
--------------------------------------------------------------------------------
|
82
|
+
/people/destroy/99 Deletes the person record having ID 99
|
83
|
+
|
84
|
+
As of Rails v1.1, scaffold controllers reject requests to insert, update and
|
85
|
+
delete records if the request is HTTP GET instead of POST. This is a safety
|
86
|
+
improvement, but the design still leaves something to be desired.
|
87
|
+
|
88
|
+
Contrast this with the HTTP interface of the equivalent trestle controller:
|
89
|
+
|
90
|
+
URL HTTP Method Result
|
91
|
+
================================================================================
|
92
|
+
/people GET or POST Lists existing person records
|
93
|
+
--------------------------------------------------------------------------------
|
94
|
+
/people/new GET Shows an empty person form
|
95
|
+
POST Creates a new person record from request
|
96
|
+
parameters
|
97
|
+
--------------------------------------------------------------------------------
|
98
|
+
/people/99 GET or POST Shows the person record having ID 99
|
99
|
+
--------------------------------------------------------------------------------
|
100
|
+
/people/99/edit GET Shows a person form for the person record
|
101
|
+
having ID 99
|
102
|
+
POST Updates the person record having ID 99 using
|
103
|
+
request parameters
|
104
|
+
--------------------------------------------------------------------------------
|
105
|
+
/people/99/destroy GET Redirects to /people/99/edit with a notice that
|
106
|
+
the user must click the form�s Destroy button
|
107
|
+
in order to destroy a record
|
108
|
+
POST Deletes the person record having ID 99 after
|
109
|
+
prompting the user for confirmation
|
110
|
+
|
111
|
+
A trestle degrades gracefully if the user has JavaScript turned off. And the
|
112
|
+
hierarchical nature of trestle URLs, wherein the ID comes before the verb, lets
|
113
|
+
the user click the Up One Level button on the Google Toolbar to explore the
|
114
|
+
application. (The Up One Level button clips one element off the end of the
|
115
|
+
current URL.) Scaffold URLs do not play nicely with the Up One Level button.
|
116
|
+
|
117
|
+
The trestle interface is not just pain relief for users without JavaScript and
|
118
|
+
those who like the Up One Level button. If you type URLs by hand, you get a
|
119
|
+
friendly notice��instead of a Rails exception��if a request is missing an ID.
|
120
|
+
There is simply less opportunity for error. That�s a tried-and-true way to up
|
121
|
+
the usability factor.
|
122
|
+
|
123
|
+
Do yourself and your users a favor by switching from scaffolds to trestles.
|
124
|
+
|
125
|
+
Visit the RubyForge page (http://trestle.rubyforge.org/) for this open-source
|
126
|
+
project. Contact me at nils@alumni.rice.edu.
|
127
|
+
|
128
|
+
-- /\/. _/.
|
129
|
+
Nils Jonsson
|
data/templates/routes.rb
CHANGED
@@ -18,12 +18,12 @@ ActionController::Routing::Routes.draw do |map|
|
|
18
18
|
map.connect ':controller/service.wsdl', :action => 'wsdl'
|
19
19
|
|
20
20
|
# Install the default route as the lowest priority.
|
21
|
-
|
22
|
-
|
21
|
+
id_requirement = /[\d]+/
|
22
|
+
action_requirement = /[A-Za-z]\S*/
|
23
23
|
map.connect ':controller/:action', :action => 'list<%= suffix %>',
|
24
|
-
:requirements => { :action =>
|
24
|
+
:requirements => { :action => action_requirement }
|
25
25
|
map.connect ':controller/:id', :action => 'show<%= suffix %>',
|
26
|
-
:requirements => { :id =>
|
27
|
-
map.connect ':controller/:id/:action', :requirements => { :id =>
|
28
|
-
:action =>
|
26
|
+
:requirements => { :id => id_requirement }
|
27
|
+
map.connect ':controller/:id/:action', :requirements => { :id => id_requirement,
|
28
|
+
:action => action_requirement }
|
29
29
|
end
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: trestle_generator
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.1.
|
6
|
+
version: 1.1.4
|
7
7
|
date: 2006-05-11 00:00:00 -05:00
|
8
8
|
summary: "[Rails] A drop-in replacement for the scaffold generator that produces production-ready controllers that are safe from state-changing HTTP GET requests and that have streamlined URLs."
|
9
9
|
require_paths:
|
@@ -11,7 +11,7 @@ require_paths:
|
|
11
11
|
email: nils@alumni.rice.edu
|
12
12
|
homepage: http://trestle.rubyforge.org/
|
13
13
|
rubyforge_project: trestle
|
14
|
-
description: "============================================================================ Trestle Generator ============================================================================ A drop-in replacement for Ruby on Rails\x92s scaffold generator Everybody loves scaffolding, and with good reason. It\x92s the feature of the Ruby on Rails framework that makes a database table editable on the web in mere seconds, and with just a few lines of generated Ruby code. The trestle generator is drop-in replacement for the Rails scaffold generator. It produces scaffolding that\x92s more like production-quality code while maintaining all the rapid goodness you know and love about Rails. Don\x92t drive your train across a gorge with nothing but a scaffold underneath it. Use a trestle instead! Trestles have two advantages over scaffolds: *
|
14
|
+
description: "============================================================================ Trestle Generator ============================================================================ A drop-in replacement for Ruby on Rails\x92s scaffold generator Everybody loves scaffolding, and with good reason. It\x92s the feature of the Ruby on Rails framework that makes a database table editable on the web in mere seconds, and with just a few lines of generated Ruby code. The trestle generator is drop-in replacement for the Rails scaffold generator. It produces scaffolding that\x92s more like production-quality code while maintaining all the rapid goodness you know and love about Rails. Don\x92t drive your train across a gorge with nothing but a scaffold underneath it. Use a trestle instead! Trestles have two advantages over scaffolds: * More elegant handling of HTTP POST and GET requests * A streamlined URL structure that makes your application easier to use Downloading and installation is a breeze with RubyGems, the package manager that\x92s included in most Ruby distributions. Just type the following at a command line: gem install trestle_generator Generating trestles for your database tables is also a one-step process: script/generate trestle YourModelNameHere ---------------------------------------------------------------------------- Why switch from scaffolds to trestles? SAFETY ---------------------------------------------------------------------------- The trestle generator produces Rails views that use HTTP POST to request changes (instead of GET). It also generates Rails controllers that execute such changes only for HTTP POST requests. Well-behaved web applications must protect user data against unwanted changes, including those arising from errant HTTP GET requests such as Google Web Accelerator is known to make. The scaffolding provided by Rails v1.1 is better about this than Rails v1.0 was, but trestles solve the problem of GET vs POST more cleanly and comprehensively. ---------------------------------------------------------------------------- Why switch from scaffolds to trestles? USABILITY ---------------------------------------------------------------------------- Trestle controllers have just four actions (index, new, edit, and destroy). Contrast this with scaffold controllers which have eight actions to implement the same functionality. This is mostly a matter of taste, but Rails developers appreciate more than most that \x93less is more.\x94 Just as important as aesthetics is the fact that trestle controllers better reflect GET and POST semantics, making for more intelligible HTTP conversations in your applications. (Apparently, Tobias L\xFCtke wrote a postback_generator RubyGem with a similar philosophy, but trestles take the concept further.) Use trestles instead of scaffolding and you will find yourself throwing away and tweaking less code as you build out applications. As joyous as Ruby programming is, less code is still a good thing. Let\x92s look at some of the differences between trestles and scaffolds. A scaffold for a database table named \x91people\x92 has the following HTTP interface: URL Result ============================================================================ /people Lists existing person records /people/list ---------------------------------------------------------------------------- /people/new Shows an empty person form ---------------------------------------------------------------------------- /people/create Creates a new person record from request parameters ---------------------------------------------------------------------------- /people/show/99 Shows the person record having ID 99 ---------------------------------------------------------------------------- /people/edit/99 Shows a person form for the person record having ID 99 ---------------------------------------------------------------------------- /people/update/99 Updates the person record having ID 99 using request parameters ---------------------------------------------------------------------------- /people/destroy/99 Deletes the person record having ID 99 As of Rails v1.1, scaffold controllers reject requests to insert, update and delete records if the request is HTTP GET instead of POST. This is a safety improvement, but the design still leaves something to be desired. Contrast this with the HTTP interface of the equivalent trestle controller: URL HTTP Method Result ============================================================================ /people GET or POST Lists existing person records ---------------------------------------------------------------------------- /people/new GET Shows an empty person form POST Creates a new person record from request parameters ---------------------------------------------------------------------------- /people/99 GET or POST Shows the person record having ID 99 ---------------------------------------------------------------------------- /people/99/edit GET Shows a person form for the person record having ID 99 POST Updates the person record having ID 99 using request parameters ---------------------------------------------------------------------------- /people/99/destroy GET Redirects to /people/99/edit with a notice that the user must click the form\x92s Destroy button in order to destroy a record POST Deletes the person record having ID 99 after prompting the user for confirmation A trestle degrades gracefully if the user has JavaScript turned off. And the hierarchical nature of trestle URLs, wherein the ID comes before the verb, lets the user click the Up One Level button on the Google Toolbar to explore the application. (The Up One Level button clips one element off the end of the current URL.) Scaffold URLs do not play nicely with the Up One Level button. The trestle interface is not just pain relief for users without JavaScript and those who like the Up One Level button. If you type URLs by hand, you get a friendly notice\x97\x97instead of a Rails exception\x97\x97if a request is missing an ID. There is simply less opportunity for error. That\x92s a tried-and-true way to up the usability factor. Do yourself and your users a favor by switching from scaffolds to trestles. Visit the RubyForge page (http://trestle.rubyforge.org/) for this open-source project. Contact me at nils@alumni.rice.edu. -- //. _/. Nils Jonsson"
|
15
15
|
autorequire:
|
16
16
|
default_executable:
|
17
17
|
bindir: bin
|
@@ -29,6 +29,7 @@ authors:
|
|
29
29
|
- Nils Jonsson
|
30
30
|
files:
|
31
31
|
- trestle_generator.rb
|
32
|
+
- README
|
32
33
|
- USAGE
|
33
34
|
- templates/controller.rb
|
34
35
|
- templates/form.rhtml
|
@@ -54,13 +55,5 @@ extensions: []
|
|
54
55
|
|
55
56
|
requirements:
|
56
57
|
- Ruby on Rails v1.0.0 or later
|
57
|
-
dependencies:
|
58
|
-
|
59
|
-
name: rails
|
60
|
-
version_requirement:
|
61
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
62
|
-
requirements:
|
63
|
-
- - ">="
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
version: 1.0.0
|
66
|
-
version:
|
58
|
+
dependencies: []
|
59
|
+
|