4 ms·
Yeah, the whole permitted params is actually is pretty shitty workaround against something else. We're missing the 'form' part. Validations should be done agai
by jbverschoor 4y ago
Yeah, the whole permitted params is actually is pretty shitty workaround against something else.
We're missing the 'form' part. Validations should be done against forms, not models. Default forms can easily be derived from models, which is nice for simple apps, but this is really something that's lacking in rails.
Permitted params exists because there is no form (dry-schema for example). There's ActiveModel, but it's not the same, and it's not ad-hoc / bound to the view/controller layer of things.
- revskill 4y agoIt's the main reason for bad legacy of many of Rails applications in the wild (noone wants to maintain the model code inside the view/controller). And it's HARD to understand why ? Omasake is bad omasake when you mix "unrelated concerns" together.
- canadianfella 4y ago[dead]
- deleted 4y ago[deleted]
- rubyfan 4y agoSounds like you want MVVM vs. the default MVC pattern Rails ships. I think there are a few options out there which are bolt on for Rails but nothing out of the box.
- bvirb 4y agoI inherited a project where all the validations were in the forms and it meant that you couldn't reliably use the model layer without the forms layer (you'd end up saving invalid data). We eventually moved the validations to the model layer and dropped the forms abstraction. It didn't feel like the right separation of concerns when we had to pretend data was moving through forms to reliably interact directly with the model layer. The enforcement of allowed params (and type casting from strings) definitely seemed like it was in the right place per-action in the control layer though, so we kept that from the forms even though we implemented it in the controllers. I wonder if we just didn't understand the idea though? Or maybe if the original implementers didn't implement it right?
- jacobsenscott 4y agopermitted params and validations are two different things though.