Skip to content

Latest commit

 

History

History
98 lines (65 loc) · 4.48 KB

generators.md

File metadata and controls

98 lines (65 loc) · 4.48 KB

Generators

Once you have Fae installed, you're ready to start generating your data model. Fae comes with a few generators that work similarly to the ones in Rails. The idea is scaffolding a model with these generators will give you a section to create, edit and delete objects.


Scaffold

rails g fae:scaffold [ModelName] [field:type] [field:type]
option description
ModelName singular camel-cased model name
field the attributes column name
type the column type (defaults to string), find all options in Rails' documentaion

This is Fae's main generator. It will create the following:

  • model
  • controller and views (_form, index, new, edit) for fully CRUDable section - the controller will inherit from Fae::BaseController
  • migration
  • resource routes
  • empty model spec file

Special Attributes

name/title will automatically be set as the model's fae_display_field.

position will automatically make the section's index table sortable, be ignored from the form and add acts_as_list and default_scope to the model.

on_prod/on_stage/active will automatically be flag fields in the section's index and ignored in the form.

_id/:references will automatically be setup as an association in the form.

:image or :file will automatically create image/file attachment associations in the model, asset builders in the controller, and file uploaders in the form.

Example

rails g fae:scaffold Person first_name last_name title body:text date_of_birth:date position:integer on_stage:boolean on_prod:boolean head_shot:image bio_pdf:file group:references

Nested Scaffold

rails g fae:nested_scaffold [ModelName] [field:type] [field:type] [--parent-model=ParentModel] [--polymorphic=true]
option description
[--parent-model=ParentModel] an optional flag that adds the association to the generated model.
[--polymorphic=true] an optional flag that makes this model and scaffolding polymorphic.

The nested_scaffold creates a nested model that is associated to a parent via a foreign key, and whose forms are meant to be nested in the parent model's form via the nested_table partial. The form has a hidden field containing the ID of the parent model. In practice the nested forms are usually only accessible when editing a parent model, not when creating one. Similar to the fae:scaffold generator, this generator creates a new model with CRUD functionality. The main differences are the automatic association to the parent model, and the views that are set up to serve the nested form. This generator creates a controller that inherits from Fae::NestedBaseController.

If the --polymorphic option is set to true, the model and scaffolding will be configured to be polymorphic. A common example of this would be a Comment model being commentable that can belong to many different parent models.

Nested Index Scaffold

rails g fae:nested_index_scaffold [ModelName] [field:type] [field:type]

The nested_index_scaffold creates new CRUD-able object similar to fae:scaffold, but there is no separate form view. All items are managed on the index view via AJAXed nested forms. The nested forms look similar to the nested forms generated by nested_scaffold, but the model created is not a nested model and has no parent. This generator creates a controller that inherits from Fae::ApplicationController.

This is helpful for objects that have very few attributes, but aren't nested under another object. E.g. categories with only a name attribute, etc.

Page

rails g fae:page [PageName] [field:type] [field:type]
option description
PageName the name of the page
field the name of the content block
type the type of the content block

The page generator scaffolds a page into Fae's content blocks system. More on that later, for now here's what it does:

  • creates or adds to app/controllers/admin/content_blocks_controller.rb
  • creates a #{page_name}_page.rb model
  • creates a form view in app/views/admin/content_blocks/#{page_name}.html.slim

Example

rails g fae:page AboutUs title:string introduction:text body:text header_image:image