Comments (5)
@mattbeedle Thanks for mentioning this idea. Our goal is to release a new version of Lotus in a month, so the deadline is really close and we can't have a look to this in the near future.
Have you tried to flatten the params to one level and let the lower components to separate those attributes?
from controller.
@mattbeedle @joneslee85 Most of the times we have single level of attributes, but grouped per entity.
Given the following form:
<form action="/books" method="POST">
<input type="text" name="book[title]" />
</form>
The raw Hash of params that comes from the Rack env is { "book" => { "title" => "Refactoring" } }
.
It doesn't work well with the actual implementation of Action.params
which only understands top level params.
Instead of having nested blocks, which adds complexity both in Action
and in Validations
, what if we introduce an optional param name like this:
params :book do
param :title # ...
end
If present it will extract and consider only that part of the Rack input.
What do you think?
from controller.
It is possible to use Virtus for nested attributes. You'd probably need to use another validation library in the Job class though.
class Job
include Virtus.model(strict: true)
attribute :title, String, required: false
end
# action
params do
param :job, type: Job
end
@jodosha I can imagine a lot of scenarios where you'd still need to access other top level parameters... for example a route parameter /jobs/:id
.
from controller.
@stevehodgkiss We use Lotus::Validations for the purpose. I would love to include nested capability there.
from controller.
Resolved by #71
from controller.
Related Issues (20)
- Ensure `Hanami::Action#initialize` to be compatible with `dry-auto_inject` HOT 1
- Regression: Return of the double-flash bug HOT 4
- Remove body cleanup for HTTP responses that doesn't require a body (e.g. 204) HOT 1
- Flash #empty? returns true when it's not (after a re-direct) HOT 2
- Hanami::Action::Flash to use swappable JSON backend HOT 2
- Flash message appears twice (redux) HOT 3
- Exception Handling in Production HOT 19
- RuntimeError: can't add a new key into hash during iteration HOT 8
- Compatability issue with hanami-controller 2.0.0.alpha1 HOT 2
- Is `#request` supposed to be memoized for actions? HOT 2
- Standalone actions prevent using non-keyword parameters in `#initialize` (v2) HOT 3
- [2.0.0.alpha1] Uninitialized constant Hanami::Controller::Configuration (NameError) HOT 2
- Handling `config` and other class-level macros HOT 3
- accept syntax in README no longer seems supported HOT 1
- Action params are not coerced? HOT 5
- Badly encoded cookie strings from Safari results in an error HOT 3
- HTTP status 418 is missing HOT 1
- Issue with multipart/form-data format HOT 1
- Support CSRF by HTTP header HOT 4
- Support for hanami-validations/dry-validations `rule(...)`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from controller.