Re: [Rails-core] Proposal for a new ActiveModel::Errors structure
Hey, It's been a while, but once again I'm working on an API-only Rails app and I have the same problem again :) Now that Rails 4.2 has been released and work on 5.0 has started, maybe it would be a good time to change ActiveModel::Errors API, so that it would allow to return translated error messages (like it does right now) *or* error codes (e.g. :invalid, :missing) that can be translated to any language by the app that's using the API? On Wednesday, 26 September 2012 14:00:26 UTC+2, Szymon Nowak wrote: On Tuesday, 25 September 2012 19:26:40 UTC+2, Aaron Patterson wrote: On Tue, Sep 25, 2012 at 06:39:58AM -0700, Szymon Nowak wrote: There are few issues with the current ActiveModel::Errors class. Firstly, when an error is added to ActiveModel::Errors class via #add method ( https://github.com/rails/rails/blob/master/activemodel/lib/active_model/errors.rb#L294) its translation is added. It should not be translated when being added, but only when being read. The second issue is a bit bigger. We'd like to create error responses in our API similar to GitHub: { message: Validation Failed, errors: [ { resource: Issue, field: title, code: missing_field } ] } Currently it's impossible to figure out which validations actually failed for a given field, as AM::Errors provides only field name and translated error message. We've got a simple workaround for this issue: module ActiveModel class Errors def error_types @_error_types ||= Hash.new{|hash,k| hash[k] = []} end def add_with_save_names(attribute, message = nil, options = {}) message ||= :invalid message = message.call if message.is_a?(Proc) error_types[attribute] message add_without_save_names(attribute, message, options) end alias_method_chain :add, :save_names end end This solution is far from perfect, but it's relatively simple and so far works for us. The best solution would be to actually build a structure similar to GitHub response - from that structure it would be trivial to build #full_messages and similar methods and it would provide a lot of additional info which would be extremely useful for creating APIs. Seems good. Can you work on a patch and send a PR? If we can maintain backwards compat, I am happy. I'll make all current methods to return the same result as they do now (even #to_json and similar methods) and use new structure only internally. The only question is how this new structure should be accessed via ActiveModel object - object.errors.errors? :) BTW. Aaron, if you have a while could you check PR about ActionDispatch::ParamsParser (https://github.com/rails/rails/pull/7444)? -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
[Rails-core] ActiveJob automatic retries
I've written an external gem for adding automatic retry support to ActiveJob, activejob-retry https://github.com/gocardless/activejob-retry. It supports constant/variable backoff, and make it super easy to define a custom backoff strategy. At present it supports Backburner, DelayedJob, Que, and Resque, and could potentially support Sidekiq too. Feels like this could be something ActiveJob supports out of the box in a future version, but thought I'd check here before doing the work to turn it into a PR onto Rails. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
[Rails-core] [ANN] Rails 4.1.9.rc1 and 4.0.13.rc1 have been released!
Hi everyone, I am happy to announce that Rails 4.1.9.rc1 and 4.0.13.rc1 have been released. This is the first release of the year and it includes a lot of bug fixes. This will be also the last release of 4.0 series as announced [in a previous blog post]( http://weblog.rubyonrails.org/2014/9/12/Rails-4-1-6-and-4-0-10-has-been-released/ ). As per our maintenance policy, the release of Rails 4.2.0 means bug fixes will only apply to 4-2-stable, regular security issues to 4.2.x, 4.1.x, and severe security issues to 4.2.x, 4.1.x, and 3.2.x. In addition to these already stated commitments, I agreed to also apply bug fixes to 4-1-stable until the Rails 5 release. As before, we will announce in a future blog post when we will drop bug fixes support for Rails 4.1. If no regressions are found expect the final release this Tuesday, on January 6, 2015. If you find one, please open an [issue on GitHub]( https://github.com/rails/rails/issues/new) and mention me (@rafaelfranca) on it, so that we can fix it before the final release. ## CHANGES since 4.0.12 To view the changes for each gem, please read the changelogs on GitHub: * [Action Mailer CHANGELOG]( https://github.com/rails/rails/blob/v4.0.13.rc1/actionmailer/CHANGELOG.md) * [Action Pack CHANGELOG]( https://github.com/rails/rails/blob/v4.0.13.rc1/actionpack/CHANGELOG.md) * [Active Model CHANGELOG]( https://github.com/rails/rails/blob/v4.0.13.rc1/activemodel/CHANGELOG.md) * [Active Record CHANGELOG]( https://github.com/rails/rails/blob/v4.0.13.rc1/activerecord/CHANGELOG.md) * [Active Support CHANGELOG]( https://github.com/rails/rails/blob/v4.0.13.rc1/activesupport/CHANGELOG.md) * [Railties CHANGELOG]( https://github.com/rails/rails/blob/v4.0.13.rc1/railties/CHANGELOG.md) *Full listing* To see the full list of changes, [check out all the commits on GitHub](https://github.com/rails/rails/compare/v4.0.12...v4.0.13.rc1). ## CHANGES since 4.1.8 To view the changes for each gem, please read the changelogs on GitHub: * [Action Mailer CHANGELOG]( https://github.com/rails/rails/blob/v4.1.9.rc1/actionmailer/CHANGELOG.md) * [Action Pack CHANGELOG]( https://github.com/rails/rails/blob/v4.1.9.rc1/actionpack/CHANGELOG.md) * [Action View CHANGELOG]( https://github.com/rails/rails/blob/v4.1.9.rc1/actionview/CHANGELOG.md) * [Active Model CHANGELOG]( https://github.com/rails/rails/blob/v4.1.9.rc1/activemodel/CHANGELOG.md) * [Active Record CHANGELOG]( https://github.com/rails/rails/blob/v4.1.9.rc1/activerecord/CHANGELOG.md) * [Active Support CHANGELOG]( https://github.com/rails/rails/blob/v4.1.9.rc1/activesupport/CHANGELOG.md) * [Railties CHANGELOG]( https://github.com/rails/rails/blob/v4.1.9.rc1/railties/CHANGELOG.md) *Full listing* To see the full list of changes, [check out all the commits on GitHub](https://github.com/rails/rails/compare/v4.1.8...v4.1.9.rc1). ## SHA-1 If you'd like to verify that your gem is the same as the one I've uploaded, please use these SHA-1 hashes. Here are the checksums for 4.0.13.rc1: ``` $ shasum *4.0.13.rc1* bf4ddb5aa6eefc6e2495a1364974a5b396d94596 actionmailer-4.0.13.rc1.gem 2bf785e91159bba8fe324e2f48a72277f2b3cf33 actionpack-4.0.13.rc1.gem f9d92979e211ce7fa71252cf1b6b4ac94c7f0b91 activemodel-4.0.13.rc1.gem d5147f64e08a3f5aed4c22ff1ebf640ca6fc0ae3 activerecord-4.0.13.rc1.gem e6f1421262fd1064e973f3d2628c6129b4c20d17 activesupport-4.0.13.rc1.gem f7416fc8485bb8a622fb50e0dd2c3fa5ca4215fa rails-4.0.13.rc1.gem 8a0690bab5e43712e8e982fe02bf76ea989f9356 railties-4.0.13.rc1.gem ``` Here are the checksums for 4.1.9.rc1: ``` $ shasum *4.1.9.rc1* 8afbb9c71a8f6e0dff26daacde407fe35aac8375 actionmailer-4.1.9.rc1.gem a5fd439bc41844a3c02671d7425bfa71d96cfbf1 actionpack-4.1.9.rc1.gem a77aaa2f936445211e7455b3228a9bfe8f27a4ac actionview-4.1.9.rc1.gem 65a7acbf9ef9b47392a48ab4c9ace44f12ea1f60 activemodel-4.1.9.rc1.gem eb66d5c52f0740114de46e1a1b76a0079c723d1f activerecord-4.1.9.rc1.gem e758d54d7fabc7d23ff995646096f40d28df42a9 activesupport-4.1.9.rc1.gem 479a31dd8d9eea3de6f444139eaefc830c6db170 rails-4.1.9.rc1.gem dae65c526ec8ee3abab9a9e8807ad7b210b7941d railties-4.1.9.rc1.gem ``` I'd like to thank you all, every contributor who helped with this release. Happy new year! :tada: -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Core group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.