Generating a Resource Scaffold
So far, you’ve already created your project and configured
your database. The next step is to use scaffolding to generate a resource.
We’ll start with a simple photo. Initially, your photo will consist of an
image in the filesystem and a record with an id
and a
filename in the database. Don’t expect Rails to build you a complete
production application. Code generators that try to do everything for you
often lead to ugly complications when you’re ready to enhance your app.
We’re looking for a head start that we can then customize. Let’s scaffold
up a resource for photos.
A List of Photos
The scaffold generator will build you a model, view, controller,
and the tests to manage them. You can see the options for generating a
scaffold by typing script/generate scaffold
:
$ script/generate scaffold Usage: script/generate scaffold ModelName [field:type, field:type] Options: --skip-timestamps Don't add timestamps to the migration file for this model --skip-migration Don't generate a migration file for this model 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) -g, --git Modify files with git. (Note: ...
Get Rails: Up and Running, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.