-
Refinements in Ruby: in map: super: no superclass method
I was trying out refinements to see if they would help clean up some parsing code. I liked defining a couple of methods for the String class to respond to, but really didn’t want them as permanent monkey patches on String. And so, I had a pipe mapping module with refinements: module PipeMapping refine String…
-
Serving a file from your Rails app from another server protected by basic authentication
Interesting problem: Retrieve a document from one web service protected by basic auth (or some authentication mechanism) and serve it via a public link on another website. It ended up boiling down to this code in the controller (reduced to be in the same method instead of factored out as it was.) def get_download response…
-
Nesting resource routes with alternate scopes and keys + strong parameters.
DISCLAIMER: This is a contrived example translated from a case where it actually made way more sense to break the familiar nested resource pattern. Also, I haven’t double-checked how Rails’ pluralization rules would affect the naming of any given Species. Say you have a pair of models: class Species # id # latin_name_with_underscores end class…