ruby-hyperloop / hyper-mesh

The project has moved to Hyperstack!! - Synchronization of active record models across multiple clients using Pusher, ActionCable, or Polling
https://hyperstack.org/
MIT License
22 stars 12 forks source link

Fix `errors!` format regression. #103

Closed sfcgeorge closed 6 years ago

sfcgeorge commented 6 years ago

When I migrated to the Rails API compatible Errors implementation I made a mistake here causing a regression. Here's an example puts showing the incorrect data format. What comes from the server is correct, but what's recreated on the client here by this method is wrong (note the erroneous hash with message: key, that should be a string):

{"success"=>false, "saved_models"=>[[362644, "IndustriesPreference", {"id"=>37, "industry_id"=>2, "preference_id"=>2}, {"industries"=>["maximum 3 industries"]}]], "message"=>"undefined local variable or method `model' for ReactiveRecord::Base:Class\nDid you mean?  models", "models"=>[<IndustriesPreference:0x58894 (0x58892) [errors {"industries"=>[{"message"=>"maximum 3 industries"}]}] >]} 

It's not entirely clear from the Rails docs how add is supposed to work, most examples pass in a symbol corresponding to an i18n message, with an optional message: key for overriding the i18n lookup. But there are 2 reasons why that can't work: the i18n bit hasn't been ported, and Opal doesn't distinguish between symbols and strings. We send the message from the server anyway rather than the i18n key so it's a moot point. Just do it this way.