Skip to main content

Context Object

Habarico can be usually configured with:

  • static values (can_read true) or
  • dynamic blocks that receive a Habarico::Context object (can_update do |c| c.policy.update? end) or
  • lambdas that also receive a Habarico::Context object.

The Habarico::Context object exposes:

PropertyDescription
current_userAuthenticated user from the request
recordThe ActiveRecord record (lazy-loaded, may be nil)
record_pkThe record's primary key
definitionThe resource's Habarico::Definition
policyPundit policy object (if Pundit is configured)
targetThe target context (e.g. ID of the parent record), used in embedded views
sourceFrom which source the action/schema is requested (e.g. { "prototype/employees" => 7 }); lets context-aware schemas resolve the originating resource/record