I think I was trying Hanami with wrong mindset. I was trying to replicate the same things I used to do in Rails apps, but now I'm trying to learn the Hanami-way before I start to tweak some things.
[#]hanami
=> More informations about this toot | More toots from ste@ruby.social
@ste I would love to read a blog post about the differences. Do you have a blog?
=> More informations about this toot | More toots from getajobmike@ruby.social
@getajobmike Not yet. I'm planning a talk about Hanami for a local Ruby community, who knows this might become a blog post in the future.
=> More informations about this toot | More toots from ste@ruby.social
@ste Ah cool. I’d love to hear your experience of what The Hanami Way is! I have some ideas about this too and I’m sure there’s much overlap but I bet we have distinct insights and preferences too.
=> More informations about this toot | More toots from cllns@ruby.social
@cllns the first thing I noticed was that the validation happens at http layer, but I'm not sure about this decision, because I think it can became complex when you need to mix with other type of validations (eg. uniqueness) and give feedback to user. So I think moving the validations to operations layer could make sense, but I'm could not integrate operation with validation contract, so I had to create a inner Contract class.
=> More informations about this toot | More toots from ste@ruby.social
@ste @cllns
There are other reasons for moving validations to the operation layer: because parameter handling is a business concern, not a framework concern.
I've heard @timriley express the view pushing validation to the farthest boundary is a way to protect your code from invalid values. @katafrakt said the same thing just recently. I would prefer to emphasize the business logic layer and keep actions boring. 😉
I hope it's okay if I follow along.
=> More informations about this toot | More toots from dcrossney@ruby.social
@dcrossney In years I discovered that most apps have two kinds of validation:
@ste @cllns @timriley
=> More informations about this toot | More toots from katafrakt@ruby.social
@katafrakt @ste @cllns @timriley
Thank you for elaborating! I appreciate that wisdom.
My thought is that if I keep the action layer as thin as possible (just know the right operation(s) to call and what view to display as a result), then I can do both in the same place.
I like the locality of related behavior. I also like that the params
block provides a kind of "type" definition for the operation. This could be used by LSPs to provide annotation and cli/IDE feedback while developing.
=> More informations about this toot | More toots from dcrossney@ruby.social
@dcrossney I haven't really figured about dry-operations and how they fit in the larger picture. But if we take your approach, won't actions become "unnecessary" proxy layer for the router? I mean, they are already separate classes, I think it makes sense to give them some responsibility.
But I feel that it's all very context-dependent and there are no simple answers.
@ste @cllns @timriley
=> More informations about this toot | More toots from katafrakt@ruby.social
@katafrakt @ste @cllns @timriley
I'm still exploring. I see Actions as handling "http concerns": request/response-related things.
Right now, my actions generally call two interactors: "get user," plus whatever resource the request needs. Then they figure out the view to display.
If the view needs more info, I think I'll call additional interactors from the View (not the template 🙄 ). Eventually some of these additional items will be lazy-loaded with htmx.
(@ste sorry for hijacking)
=> More informations about this toot | More toots from dcrossney@ruby.social
text/gemini
This content has been proxied by September (3851b).