# "Best practice" for doing CRUD?

**URL:** <https://www.ruby-forum.com/t/best-practice-for-doing-crud/69803>\
**Category:** Rails\
**Created:** [September 24, 2006, 5:28am UTC](https://www.ruby-forum.com/t/best-practice-for-doing-crud/69803 "2006-09-24T05:28:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [September 24, 2006, 5:28am UTC](https://www.ruby-forum.com/t/best-practice-for-doing-crud/69803/1 "2006-09-24T05:28:39Z")

</div>

I’m trying to stop worrying and love the crud.

One of the insights I’ve gained so far from the CRUD philosophy in Rails  
is to view my domain objects as resources that the client can access.  
(Don’t know why, it seems so obvious now, but I never really thought of  
a web app quite that way before).

So let’s say I start a new Rails project and I’m about to add my first  
resource. I’m on edge rails.

Here’s what I usually do:

1. Create the REST controller: ruby script\generate controller Things  
index create new show update edit destroy
2. Use html verbs: map.resources :things
3. Usually, create a model: ruby script\generate Thing
4. Edit the Thing migration script as needed
5. rake migrate
6. rake (just to feel good that all my tests still pass)

My questions:

1. I think DHH demostrated a new generator at Rails Conf in Europe;  
anybody know if that’s made it into edge rails yet? If so, how do I use  
it?
2. Am I missing anything obvious?

Thanks!  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [September 24, 2006, 6:14am UTC](https://www.ruby-forum.com/t/best-practice-for-doing-crud/69803/2 "2006-09-24T06:14:42Z")

</div>

On Sep 23, 2006, at 8:28 PM, Jeff C. wrote:

> So let’s say I start a new Rails project and I’m about to add my first  
> 6. rake (just to feel good that all my tests still pass)  
> Jeff  
> Since you are on edge rails you can use the new scaffold\_resources.

script/generate scaffold\_resources things title:string foo:text  
created\_at:datetime updated\_at:datetime

-Ezra

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [September 24, 2006, 6:52am UTC](https://www.ruby-forum.com/t/best-practice-for-doing-crud/69803/3 "2006-09-24T06:52:45Z")

</div>

> Since you are on edge rails you can use the new scaffold\_resources.
> 
> script/generate scaffold\_resources things title:string foo:text  
> created\_at:datetime updated\_at:datetime

Ezra, are you sure it’s committed yet?

C:\dev\>ruby script\generate scaffold\_resources  
Couldn’t find ‘scaffold\_resources’ generator

I have edge revision 5170 (performed a rails:freeze + rails:update just  
a few minutes before my original post).

Thanks!  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [September 25, 2006, 2:24am UTC](https://www.ruby-forum.com/t/best-practice-for-doing-crud/69803/4 "2006-09-25T02:24:54Z")

</div>

Ezra Z. wrote:

> Yeah its in there for at least a week or so. I just used it. It  
> actually is scaffold\_resource singular while in its usage text it  
> says scaffold\_resources 😉
> 
> ez ey $ script/generate scaffold\_resource  
> Usage: script/generate scaffold\_resources ModelName

Awesome. Thanks Ezra.

Jeff

> **[Hey Daddio!](http://softiesonrails.com)**
>
> Home of Hey Daddio Software

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [September 24, 2006, 7:24am UTC](https://www.ruby-forum.com/t/best-practice-for-doing-crud/69803/5 "2006-09-24T07:24:46Z")

</div>

On Sep 23, 2006, at 9:49 PM, Jeff wrote:

> C:\dev\>ruby script\generate scaffold\_resources  
> Couldn’t find ‘scaffold\_resources’ generator
> 
> I have edge revision 5170 (performed a rails:freeze + rails:update  
> just  
> a few minutes before my original post).
> 
> Thanks!  
> Jeff

Hey Jeff-

```
Yeah its in there for at least a week or so. I just used it. It

```

actually is scaffold\_resource singular while in its usage text it  
says scaffold\_resources 😉

ez ey $ script/generate scaffold\_resource  
Usage: script/generate scaffold\_resources ModelName

Rails Info:  
-v, --version Show the Rails version number  
and quit.  
-h, --help Show this help message and quit.

General Options:  
-p, --pretend Run but do not make any changes.  
-f, --force Overwrite files that already  
exist.  
-s, --skip Skip files that already exist.  
-q, --quiet Suppress normal output.  
-t, --backtrace Debugging: show backtrace on  
errors.  
-c, --svn Modify files with subversion.  
(Note: svn must be in path)

Description:  
Explain the generator

Example:  
./script/generate resource\_generator Thing

```
 This will create:
     what/will/it/create

```

-Ezra
