Examples

Examples of how to use various parts of ICMS.

Hide Actions for Resource

Let's say you have a Message model that you use for saving messages from end users filling out a contact form. You might want to remove the possibility of editing and deleting these records from the administration interface. To achieve this you have two basic strategies to choose from:

Using the Authorization System

If you have chosen an authorization system it might be enough to remove the ability to edit and delete the Message records for all roles. This is a fast and simple solution that probably is recommended in most cases. It comes with one caveat though - any authorizer that belongs to a role with "Super Administrator" privileges will still be able to edit and delete the resources. This may or may not be a good thing.

Using the disable_resource_actions Dashboard Helper Method

In the MessageDashboard we can disable the edit and delete actions completely for all authorizers:

# app/dashboards/message_dashboard.rb
class MessageDashboard < IcmsBackend::BaseDashboard
  disable_resource_actions [:edit, :delete]
end

A disable_custom_actions method is also available from removing custom actions.

Exporting Resources

Simple CSV exporting is enabled by default and all you need to do is point to the index of your resource, adding the ".csv" extension. For example if you have posts at /admin/posts, pointing to /admin/posts.csv will allow you to download a CSV representation of all your posts.

In order to customize which attributes are included in the export you can override the EXPORT_ATTRIBUTES array in your dashboard:

EXPORT_ATTRIBUTES = [
  :id,
  :title,
  :created_at
]

At the moment only CSV exports are provided by icms but you may add an index.x to support any format you need (app/views/icms_backend/application/index.x).

results matching ""

    No results matching ""