I am using the Hyperstack.org framework, so working with Opal compiled Ruby code. Hyperstack's integration with Rails creates a representation of some of the Models on the client and I have a question about error validation in the response.
When saving a Model with validators, when one of the validators is triggered I am unable to get the full error message in the promise response.
In this code:
@User.save(validate: true).then do |result|
if result[:success]
puts 'successs'
mutate @open = false
else
result[:models].each do |response_model|
puts "response_model.errors.class = #{response_model.errors.class}" #ActiveModel::Errors
puts "response_model.errors.full_messages = #{response_model.errors.full_messages}" #nothing puts
end
end
The first puts returns #ActiveModel::Errors
but I seem unable to use the methods of that model.
I can see the tests for this: https://github.com/hyperstack-org/hyperstack/blob/a09bc601b3ad289c9f75156416ed39dff88059c9/ruby/hyper-model/spec/batch1/misc/errors_spec.rb#L340 so I would expect this to be working and it must be me!
Also, I have noticed that that JSON response to the promise does actually include the error message:
{
"success" => false, "saved_models" => [
[227154, "User", {
"id" => 48,
"first_name" => "ds",
"last_name" => nil,
"email" => nil,
"image_src" => nil,
"date_of_birth" => nil,
"is_admin" => false,
"is_female" => false,
"is_enabled" => true,
"created_at" => "2019-03-23T12:29:05.728Z",
"updated_at" => "2019-03-23T12:29:05.728Z"
}, {
"last_name" => ["can't be blank"]
}]
], "message" => "HyperModel saving records failed!", "models" => [ < User: 0x37752(0x37750)[errors {
"last_name" => ["can't be blank"]
}] > ]
}
Any help appreciated!
Looks like you hit a bug in HyperModel with the full_messages
method. AFAIK all the other methods would work fine in your example.
If you look at https://github.com/hyperstack-org/hyperstack/issues/143 there is a work around patch to apply if you really need full_messages