-
-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validating nested params #53
Comments
@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? |
@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 Instead of having nested blocks, which adds complexity both in params :book do
param :title # ...
end If present it will extract and consider only that part of the Rack input. |
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 |
@stevehodgkiss We use Lotus::Validations for the purpose. I would love to include nested capability there. |
Resolved by #71 |
Hey,
It doesn't seem to be possible to validate nested params at the moment. I was hoping this syntax would work:
The text was updated successfully, but these errors were encountered: