User:ISuite: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 99: Line 99:
Generator->scaffold
Generator->scaffold


Step -5. In parameters specify the model, fields and their type
Step -5. In parameters, specify the model, fields and their type


Step -6. Here we take, Car color:string maker:string year:date
Step -6. Here we take, Car color:string maker:string year:date
Line 105: Line 105:
Step -7. This will run the generate script and create files in View, controllers, model, db etc as shown below:  
Step -7. This will run the generate script and create files in View, controllers, model, db etc as shown below:  


>script/generate scaffold Car color:string maker:string model:number year:date
                >script/generate scaffold Car color:string maker:string model:number year:date

Revision as of 22:15, 22 September 2010

Scaffolding in Web Application Frameworks

Overview

Scaffolding in General

Scaffolding in education is basically the support a teacher gives to a new student to get him started on his subject. Scaffolding is also the temporary structure often used by workers in construction. So what we know of the word scaffolding in real world – a temporary structure to lean on while you build the main structure. The temporary structure can then be discarded.

Scaffolding in Programming

It is with the same basic idea that scaffolding in web programming frameworks refer to. It refers to a temporary structure, which is useful as a starting point for the novice. Scaffolding is nothing but a basic temporary structure that helps a new programmer to get started quickly. It is meta-programming method to quickly generate a functioning web application with the CRUD functionality. Any web application that interacts with database has 4 basic functions generally called CRUD, which it always needs and these are:

  • Create a record,
  • Read,
  • Update or
  • Delete a record.

A scaffold will generate a functioning web application that allows you to carry out these functions. Usually you get a running web application with not more than a few lines of code. It generates for you what is often termed as boilerplate code. In a MVC framework, scaffolding will usually create basic model, views and controllers and also the database objects needed.

Features of Scaffolding

In software applications, we need to use a number of frameworks to make application run. The frameworks may include:

  • Database access
  • Screen design, and
  • Business rules

And scaffolding is the mechanism by which we can create the skeletal of the web application at first go. So, now after having some basic concept of scaffolding, we can list out the main features of scaffolding below,

  • It is a framework that provides the minimal setup of the components like database, application servers, and web servers.
  • When you want to use the structure early on in the development cycle when you are experimenting with the database schema and layout, it helps to quickly generate basic functional application for you directly from the database schema.
  • Scaffolding helps when the schema undergoes refinement and you don't need to waste your time to change the views and controllers explicitly to align with the change.
  • It isn't what you would like to use directly in your production systems, you can eventually make changes as you move on with your added and updated project requirements.

History of Scaffolding

Origin and evolution

Scaffolding Theory

Scaffolding theory in education came into being in 1950, by, Jerome Bruner, where he described the various scaffolding techniques for oral language and written vocabulary. In Oral scaffolding, parents and adults help the children to make them know how to speak and communicate, how they should use the words and develop the base or a temporary framework for their children to walk in the new world. And once the child secures the control over the things, base can be taken away. Similarly, in written scaffolding, typical supporting instructions were given by the instructor to the students to learn vocabulary, to calibrate the task, to identify the task and work independently on the task, in this way they built the scaffold for them on which they can lean on while learning. So children use oral scaffolding as a vehicle to communicate and written scaffolding as tool for new thinking. And the teacher’s instructions also get changed from time to time, starting from the directions, to suggestions, to encouragement, and then observation.

Scaffolding Origin in Web Applications

Scaffolding has been around in various forms for some time. Earlier, separate code generators were written, which would generate CRUD functionality for certain frameworks. They were often the third party generators who offered varying capabilities and mainly acted as database code generators.

You could also have custom scripts, which could generate the CRUD screens from some database specifications. Often each new project involved writing up some templates to get the basic functionality or write a template generator script, which created these templates for your project. But these generators and scripts were non-standardized and often viewed as taking away time from the core development of an application.

Scaffolding in education is basically the support a teacher gives to a new student to get him started on his subject. Scaffolding is also the temporary structure often used by workers in construction.

So what we know of the word scaffolding in real world – a temporary structure to lean on while you build the main structure. The temporary structure can then be discarded.

What scaffolding is Today?

Current Scaffolding Scope

Scaffolding is now a part of many web application frameworks. We can find a number of development software’s that uses web application scaffolding approach. Frameworks may include,

  • Ruby on Rails,
  • CakePHP ,
  • ASP.NET
  • CodeIgniter
  • iPhone Web Scaffolding
  • Grails

These frameworks actually contain some software components that create the skeletal attachments to the application’s database and other external devices. We will see how this scaffolding works in some of the frameworks described above in next few paragraphs.

Benefits of Scaffolding

We have noticed, that scaffolding makes the developers job easier, and rather than making a lot of configuration changes at the very first time or may be at the time of updations, he can concentrate on the business logic of the application, which saves his lot of time that he may have spent in creating and maintaining the database code. So you can read out the benefits of Scaffolding below,

  • It acts as a tool for the developers to quickly generate running web application environment for the Internet.
  • It provides modular stubs to perform typical CRUD implementations.
  • It improves development productivity for system architects.
  • It improves efficiency by creating reusable components for developers by using frameworks and code generators.

Example of Scaffolding in CRUD Framework

Here we will describe how the scaffolding approach works in Rails frameworks. Scaffolding gets its popularity with the rails framework only, and it comes as the inbuilt feature of the rails framework.

Scaffolding in Rails Framework

Now lets see how scaffolding in the rails framework helps to create the database schema at the start of an application by using very simple commands. Rails scaffolding helps to create model, view and controllers for the new resource in a single operation. Follow these steps in the Eclipse IDE to create a scaffolding of a car website.

Step -1. Create New Rails Project: New->New Rails Project

Step -2. Get the generator view: Window->Show View->Generators

Step -3. Make sure current project for Generator is the project that you want.

Step -4. Select the scaffold generator from drop down box: Generator->scaffold

Step -5. In parameters, specify the model, fields and their type

Step -6. Here we take, Car color:string maker:string year:date

Step -7. This will run the generate script and create files in View, controllers, model, db etc as shown below:

               >script/generate scaffold Car color:string maker:string model:number year:date