Orma::Record
Inherits Reference < Object
Macros
accessible(access_model, target_resource, refreshed_template, &blk)
Provides the capability to share records via access tokens.
Adds the following to the model:
- An
access_tokencolumn that will be populated automatically - The
access_viewmacro which defines a template to be shown when opening a link containing theaccess_tokenaccess_viewcan be called in the block of theaccessiblecall
- A page providing the
access_viewtemplate- The path will be
/<model_name>/access/<access_token>
- The path will be
#share_uri, returning the full URI to open theaccess_view#share_element, returning a wrapper template that will attempt to trigger sharing capabilities on the client device on click- Sharing the
#share_urivia the Web Share API (mostly on mobile devices) - Writing the
#share_urito the device clipboard via the Clipboard API (usually only available in secure contexts)
- Sharing the
- A model action to accept access
- Its visible template can be defined via the
accept_access_viewtemplate macro - Should be included via
#accept_access_action_templatein theaccess_viewtemplate
- Its visible template can be defined via the
- The
access_model_attributesmacro, accepting a NamedTuple parameter- The given attributes will be added to the access model instance that is created when a user accepts the access via the model action
NOTE: This macro is about sharing and granting access, not about restricting it. Any Resource showing this model has to be made aware of any restrictions by other means.
Example usage:
class GroupMember < ApplicationRecord
column session_id : String
end
class Group < ApplicationRecord
[...]
model_template :member_list do
[...]
end
accessible GroupMember, GroupResource, member_list do
access_view do
template do
h1 { "Join!" }
model.accept_access_action_template
end
end
accept_access_view do
template do
button { "Join" }
end
end
access_model_attributes session_id: ctx.session.id.to_s
end
end
boolean_flip_action(name, attr, tpl, &blk)
Sourcecreate_child_action(name, child_class, parent_id_attr, tpl, &blk)
Defines a model action that creates a child record and merges:
parent_params- submitted form values
- optional
context_attributes
Form blocks in model actions are model-aware by default (Crumble::ModelForm),
so option helpers can directly access model.
Example:
create_child_action :create_reimbursement, Reimbursement, group_id, default_view do
form do
field amount : Float64, attrs: {required: true, step: ".01"}
field recipient_membership_id : Int64, type: :select, options: recipient_options
def recipient_options
options = [{"", t.form.recipient_membership_id_prompt}] of Tuple(String, String)
model.group_memberships.each do |membership|
next if membership.user_id == ctx.session.user_id
options << {membership.id.value.to_s, membership.display_name}
end
options
end
end
end
delete_record_action(name, tpl, &blk)
Defines an action to delete the record from the database. Parameters:
name- the name of the actiontpl- the model template to render in the response
model_action(name, refreshed_model_template, base_class = Orma::ModelAction, &blk)
Sourcemodel_template(method_name, wrapper_attributes = nil, &blk)
Sourcereorder_children_action(name, assoc, child_view, tpl, &blk)
Defines an action to make a list of child models sortable via dragging. Parameters:
name- the name of the actionassoc- method of the parent model returning the children collectionchild_view- method of the child model returning the template to use in the sortable listtpl- the model template to render in the response