Category: daily learning

  • 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…