6

Slimmer ActiveModel::Errors#inspect message by lulalala · Pull Request #42832 ·...

 3 years ago
source link: https://github.com/rails/rails/pull/42832
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Contributor

lulalala commented 3 days ago

edited

Summary

For ActiveModel::Errors, only show @errors array and hide @base.

@base is not the core information developers are looking for in an Errors object, and they would have access to @base before getting access to errors anyways.

In the past we would see a very long string, and only to find out at the very end it is empty:

#<ActiveModel::Errors:0x00007ff68cda24f8 @base=#<Foo id: 6, created_at: "2021-07-09 04:28:48.056662000 +0000", 
updated_at: "2021-07-09 04:28:48.168576000 +0000", email: "[email protected]", name: "Foo Bar", company: "Foo",  
activated_at: "2021-07-09 04:28:39.039853000 +0000">, @errors=[]>

Now it would just be

#<ActiveModel::Errors []>

Or if it is not empty:

#<ActiveModel::Errors [#<ActiveModel::Error attribute=base, type=invalid, options={}>]>

Other Information

I thought since ActiveModel::Errors is now wrapping around the array, it makes sense to display the information as an array.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK