Skip to content

Scaffold

sh
rails g trek:scaffold Book title intro:text

Akin to Rails', Trek's scaffold generates, with a single command:

  • the Book model and migration (calling the Rails model generator behind the scenes)
  • the Admin::BooksController, inheriting from Trek::ResourceController
  • the Slim views: index, show, new, edit and the _form partial
  • the Admin::BookPolicy, inheriting from Trek::ResourcePolicy
  • the resources :books route in the admin namespace
  • the locale files for the model and its admin panel, in every configured locale (auto-translated via DeepL when DEEPL_AUTH_KEY is set)
  • the entry in the admin dashboard menu

Field types

Standard Rails attribute types are supported (string, text, integer, float, decimal, boolean, date, datetime, references…) and mapped to the matching form helpers: text renders the content editor, boolean a switch box, references a collection select, and so on.

Opt-in concerns

The generated model ships with commented-out hooks for Trek's most useful concerns, ready to be enabled when needed:

ruby
class Book < ApplicationRecord
  # include Trek::Formattable
  # format_attributes Trek::TypographyFormatter, :title

  # include Trek::Translatable
  # translate_attributes :title

  # include RecordImageUploader::Attachment(:image)

  strip_attributes
end

Released under the MIT License.