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 […]

has_one, reject_if, and accept_nested_attributes still fails validation

Problem What I wanted to accomplish in my form was allowing an Account to manage a Devise user account. Parent model code: class Account has_one :service_user accepts_nested_attributes_for :web_service_user, :allow_destroy => true, :reject_if => :password_not_specified, :update_only => true def password_not_specified(attributes) attributes[:password].blank? end end Child model code: class ServiceUser devise :database_authenticatable belongs_to :account validates_uniqueness_of :username validates_presence_of :password, […]

Unable to find any JVMs matching version “1.7” and Mac OS X Mavericks can’t see JAVA_HOME

Background: My .zlogin had a call to /usr/libexec/java_home 1.7 to set the JAVA_HOME to that of my Java 1.7 install, but it was an artifact of my former Mac OS X Lion configuration. I finally decided to “fix” the problem by installing JRE 7, but found my JAVA_HOME to be /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java, and then found […]

.zlogin (or .zshrc) parse error near `\n’

This code was at the end of my .zlogin on my mac and was causing .zlogin:152: parse error near `\n’. The problem is rather bone-headed, but I went through trying to :set ff=unix, :set ff=mac in vim to try and remedy bad line endings. function notify_preexec() { # Note the date when the command started, […]

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 […]

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 […]

Git wrapper for vim: fugitive.vim

Today’s browsing through “plugins that I haven’t made good enough use of” brings me to vim-fugitive: :Gstatus pulls git status output into a vim split window. Pressing – on the line that a file is listed on either adds or removes a file from staging, and :Gcommit commits it. :Gdiff opens a vertical split next […]