Tuesday, January 25, 2022

Generators and scaffolds (scaffolds and generators)

 




Generators and scaffolds (scaffolds and generators)




GENERATOR


A generator is a program (script) that writes programs (or code fragments) according to given input parameters. Since the absolute majority of ROR application fragments are maximally unified (consistent with ROR standards), we have the opportunity to create programs that will independently generate beautiful working code for some fragments of our application.

So, for example, most of the actions taking place on the site fall into the category of CRUD (Create, Read, Update, Delete)Let's take a user profile - there must be functions for it - create, read (view), update, delete. It's the same with site pages, each should be able to be created, read, updated and deleted. These actions have a completely similar algorithm, the only difference is the name of the object class to which the algorithm is applied (Profile and Page).

Generators are known that, according to the given object names, create completely ready-to-execute logic files (functions, request handlers), display types, and so on. So we can in a matter of seconds, using the generator, create very simple, but full-fledged administrative web interfaces.

Scaffold, scaffolding (scaffold, scaffold generator)


The scaffold is a generator that creates a completely ready-to-use administrative interface for managing database objects through a web browser.
As input data, it takes the name of the Model (object class) and a list of database table fields with the corresponding data types (in order to create a corresponding input element inside the html form for each data type). Provides a complete set of CRUD actions.

The scaffold generator embodies one of the RAILS ideologies - DRY (DON't REPEAT YOURSELF) - i.e. don't repeat yourself (don't rewrite your code). Indeed, by creating a generator to create files with similar functionality for different fragments of the application, we largely save ourselves from having to write the same code repeatedly.

Scaffold (scaffold) - in translation means scaffolding or scaffolding. Those. creates something that allows you to quickly build an interface.

Generators and scaffolds (scaffolds and generators)

  Generators and scaffolds (scaffolds and generators) GENERATOR A generator is a program (script) that writes programs (or code fragments) a...