6. Pre-fill a field from the current user
Most users operate on one default workflow. You want the schema's default for workflow_id to be that user's default, not a hardcoded constant.
Problem. Most users operate on one default workflow. You want the schema's default for workflow_id to be that user's default, not a hardcoded constant.
Solution. Tag with @default_for(:key) and implement default_for on your user.
#: (
#: applicant_id: String,
#: workflow_id: String @default_for(:workflow_id)
#: ) -> Hash[Symbol, untyped]class CurrentUser
def default_for(key)
case key
when :workflow_id then defaults[:workflow_id]
end
end
endResult. A manager's schema shows "default": "wf-executive-hiring"; an operator's shows "default": "wf-standard-hiring". Same param, personalized default, resolved per request. default_for is optional โ skip the tag and you never need the method.
Want a static default instead? Use
@default(value)โ it takes literals:true,false,nil, numbers, or strings.
Collected from COOKBOOK.md in the repository. Edit it there, not here.