21

I am running

ruby script/generate scaffold

or

ruby script/generate model

and I know the basic syntax, like

ruby script/generate scaffold Dude name:string face:boolean

but I do not know things like:

  • should names of variables have underscores or be camelCased?
  • what kind of variable types are acceptable?

Where can I find such information?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
  • 2
    Note: With Rails 3 a lot of the old information is out-of-date. Current information about the script generators is at [A Guide to The Rails Command Line -> rails generate](http://guides.rubyonrails.org/command_line.html#rails-generate) – the Tin Man Dec 01 '10 at 03:39
  • thanks @Greg, gotta get my Rails 3 on now. – Dan Rosenstark Dec 02 '10 at 23:25
  • 1
    Rails 3 is a nice improvement. It's still a steep learning curve but it's not as bad as it once was. – the Tin Man Dec 02 '10 at 23:40

5 Answers5

27

Type the command without arguments and the documentation is revealed:

$ script/generate model

You can use either camelcase or underscores for the model name.

  • Model names are singular; controller names are plural.
  • Field names use underscores.

I can't remember all the possible field types, I just look them up from the Migration docs, as linked above.

Andrew Vit
  • 18,961
  • 6
  • 77
  • 84
10

This document on Rails Migration would help.

With respect to the naming convention, I think the general adopted convention for Ruby on Rails is to have underscores.

To know which variable types are acceptable, refer to the section on Database Mapping.

Ronnie Liew
  • 18,220
  • 14
  • 46
  • 50
6

There is a resource on the rails wiki as a List of Available Generators.

Doug Porter
  • 7,721
  • 4
  • 40
  • 55
drew.macleod
  • 143
  • 1
  • 6
3

To check Rails naming conventions, topfunky's Pluralizer was useful.

Eric Davis
  • 1,837
  • 14
  • 15
2

there is a new syntaxis for Rails is rails generate

igor
  • 21
  • 1