Hi! Started using Hanami for real now that 2.2 was announced. This is about receiving arbitrary hash keys.
The app is used for registrations: Seasons have many Events, Events have many Registrations. The UI displays a Season and all attending seasons. People register one or more events, and could register themselves for multiple times for multiple events. For example:
- Season 2024-2025
- 2024-10-01 10 am
* 4 slots remaining - 2024-10-01 noon
* 2 slots remaining
- 2024-10-01 10 am
On the same form, I can register myself and another for the 2024-10-01 slots as well as a 3rd person for the 10 am slot: I register 3 people for 2 different slots.
The schema I planned to receive is (rendered as JSON for readability):
{
"registration": {
"email": "john.smith@example.com",
"vpld": {
"new0": {
"name": "john smith",
"role": "string"
}
},
"hyuk": {
"new0": {
"name": "john smith",
"role": "string"
},
"new1": {
"name": "jane smith",
"role": "string"
},
}
}
In this schema, vpld
and hyuk
are event slugs. new0
and new1
are simple indicators; it could be an array and I would be fine.
The schema I have declared in my action is:
params do
required(:slug).filled(:string) # coming from URL
required(:registration).hash do # form parameters
required(:email).filled(:string) # should be enhanced to :email
# how do I declare that I will receive arbitrary strings as keys?!?
hash do
hash do
required(:name).filled(:string)
required(:role).filled(:string)
end
end
end
end
I am open to changing my schema; that wouldn’t be an issue for me.
Any help appreciated!
François
PS: I understand the params
block is coming from dry-schema or dry-validation, but if we want to make Hanami successful, these types of questions will have to be answered here. If it is preferable, I will ask the question in another forum.