-
has_many :through, scoped to a value on the other side of the :through relationship
Here goes another round of wrapping my head around what rails associations are looking for. This time, I’m trying to scope a collection on the other side of a has_many :through to an attribute on that model. Contrived exhibit A: class Gym < ActiveRecord::Base # gym has a boolean "open" end class TrainerGym < ActiveRecord::Base…
-
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…
-
Moving Static Files to the Assets Pipeline (upgrading from 3.0 to 3.1+)
For those who have done the upgrade, this is probably second nature: Recently stumbled upon static files in the public/javascripts directory and wanted to get them moved to the $RAILS_ROOT/app/assets/ directory. This RailsCast, 282 Upgrading to Rails 3.1 provides most of the notes you need on doing this. The first key is to include: config.assets.enabled…