简体   繁体   中英

What does “scaffold” mean in Ruby on Rails?

I am studying a guide in which scaffold is mentioned. I don't understand what it is.

Is it sort of built-in framework?

see rails guide for the explanation

Rails scaffolding is a quick way to generate some of the major pieces of an application. If you want to create the models, views, and controllers for a new resource in a single operation, scaffolding is the tool for the job.

Scaffolding in Ruby on Rails refers to the auto generation of a simple set of a model, views and controller usually for a single table.

For example:

user@localhost$ ./scripts/generate scaffold users

Would create a full CRUD (create, read, update, delete) web interface for the Users table. Of course features like hashing the password, uploading images, etc... are not handled and must be added to the auto-generated code.

I'm also studying Ruby On Rails from the scratch. Here is how I remember it: Each scaffold is an object inside your application, that users will interact with. User can create this object, or update, or read, or delete. At facebook one of this objects is status . Each user can create it, read, delete or update status . At twitter it's tweet . At pinterest it's pins .

Every applications contains a lot of such objects — statuses, photos, comments, users, etc. You just have to plan all of then and design future interactions between this objects and users of your application.

In rails 3.2 when you type this in the TERMINAL, inside your rails app folder:

rails generate scaffold User
  • the "User" part could be any name you choose...

  • it creates all of the the structure for your CRUD (create, read, update, delete)

  • in this creation it includes the controller, model, and views the views for each part of the CRUD (create, read, update, delete),

  • and the code inside them to start you off with your CRUD (create, read, update, delete)

  • its way easier to do this, instead of coding everything yourself, it saves you lots of time!

lets have a simple example

we want to have an app with two data model one is user model with user_id,name and email and another is the post model with id and content.

we want to associate each post model with a particular user. we will accomplish this by recording the user_id of the owner of the post.

by using rails scaffolding command you can create rails scaffold command rails will generate the models and controller for the two data model.

you can save a lot of time

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM