Frage

I am having a question on scaffolding. Can someone explain what it does and how it works. I have search Google but I couldn't find anything that explained all the steps that happens.

War es hilfreich?

Lösung 2

When I run the command:

rails generate scaffold peoples name:string age:integer

The following happens:
+ Rails connects to the database (defined in databases.yml) and creates a new table called peoples
+ In that table it creates two columns named name and age
+ Now it creates the web page that allows you to interface with the table
Scaffolding gives you a quick start on your Ruby on Rails projects.

Andere Tipps

A simple search in Google provides a lot of information. Also wikipedia

http://en.wikipedia.org/wiki/Scaffold_(programming)

Long story short a scaffold is simply a utility that most MVC web frameworks provide to create the necessary code/files for simple CRUD operations in the application.

In Rails, this means it will create the following from bottom up:

Active Record/Models

  1. Migrations: These are used to create the necessary tables/columns for the model.

  2. Models: Self explanatory, class of the model that subclasses from ActiveRecord::Base

Resource Routes

  1. resources: :model: It generates the CRUD routes: index, show, new, create, edit, update, destroy by placing the resources: :model_name line in the routes.rb file.

ActionController

  1. Controller: The controller that ties in the routes with the models and views with necessary code to perform the CRUD operations.

ActionView

  1. Views: The views that display a very simplistic UI for performing the CRUD operations.

  2. Assets: The javascripts, images, css, that are used in the views. This is very modular thanks to the assets pipeline.

It creates a bunch of other stuff based on your choices of test libraries. You can actually see what it's doing by just running rails scaffold SomeModel.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top