Skip to content

How To: Disable Default Actions

Seoung Ho Jeong edited this page Jun 29, 2024 · 2 revisions

There are 7 default actions in Trestle:

  1. index: Displays a list of resources.
  2. show: Displays a single resource.
  3. new: Displays a form for creating a new resource.
  4. create: Handles the creation of a new resource.
  5. edit: Displays a form for editing an existing resource.
  6. update: Handles the update of an existing resource.
  7. destroy: Handles the deletion of a resource.

You can customize these actions or remove them as needed. For example, in the users_admin.rb file, the :new and :create actions are removed:

Trestle.resource(:users, model: User, scope: Auth) do
  remove_action :new, :create
  # ... existing code ...
end

This customization allows you to tailor the admin interface to your specific requirements.

Readonly option

You can also set a resource to be read-only by using the readonly: true option. This will only enable the index and show actions:

Trestle.resource(:name, readonly: true) do
  # ... existing code ...
end

When you set a resource as read-only, the new, create, edit, update, and destroy actions are automatically disabled. This is useful for resources that should not be modified through the admin interface.