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.
rails g fae:scaffold [ModelName] [field:type] [field:type]
|singular camel-cased model name
|the attributes column name
|the column type (defaults to
string), find all options in Rails’ documentaion
This is Fae’s main generator. It will create the following:
name/title will automatically be set as the model’s
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.
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
rails g fae:nested_scaffold [ModelName] [field:type] [field:type] [--parent-model=ParentModel] [--polymorphic=true]
|an optional flag that adds the association to the generated model.
|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.
--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.
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.
rails g fae:page [PageName] [field:type] [field:type]
|the name of the page
|the name of the content block
|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:
rails g fae:page AboutUs title:string introduction:text body:text header_image:image