-
Getting a count of the rows in all of your ActiveRecord models
Warning: Going through ActiveRecord is likely not something you want to do in production unless you have a replica database that your script or your model can point at. See the second part for MySQL and PostgreSQL examples in SQL. How do you enumerate your models? For apps created under Rails 5 app or later,…
-
Rails’ and Ruby’s Hash transform_values
Rails: 4.2.1-5.2.3 and Ruby >= 2.5.5 have a transform_values method on Hash that allows you to pass a block to the method and transform the values of the key-value map in the hash based on the block contents. Essentially, it’s map but for the Hash values only, and with no weird Hash/array-element syntax. From the…
-
XML Handler Bypassing ParseError Handling Rack Middleware on Rails 6
In a project using actionpack-xml_parser, and implementing a modified version of Catching Invalid JSON Parse Errors with Rack Middleware to also handle XML errors, an upgrade to Rails 6 broke the handling of the ParseError. Interestingly enough, JSON was being handled as expected. TL;DR: The short answer to this is that config/initializers/wrap_parameters.rb only had json…