I'm Jason, a web applications developer in the Denver, Colorado area.

  1. Paperclip error with non-image file

    Recently I updated to Rails 3.1 from 2.3.8 for a project I’m working on. Paperclip version 2.4.5 was working perfectly well for me locally on my Mac OS X 10.7.2 laptop, with ImageMagick version 6.7.3-1.

    We had just launched the upgraded Rails 3.1 application to our production server, which went smoothly, but upon my checklist of pages to test (we don’t have test suite in use yet) I noticed that the file upload was failing. Further investigation showed that the object using paperclip was failing to save:

    #["/tmp/stream20111205-28441-10oj2ck-0.csv is not recognized by the 'identify' command.", "/tmp/stream20111205-28441-10oj2ck-0.csv is not recognized by the 'identify' command."]}>, @base=#>

  2. Issues with RVM

    I recently decided to check out BrowserCMS, to evaluate how it work and decide to use it…or RefineryCMS. I didn’t expect that BrowserCMS would require Ruby 1.9.2. I’ve been running with Ruby 1.8.6 or 1.8.7 for quite a while now without any issues. It looks like it was time that I install RVM: Ruby Version Manager.

    I read through the documentation, followed the instructions to ensure that prerequisite software was installed. I specifically made sure that certain commands that it stated would be needed were all in my command line path under /opt/local, where the MacPorts all install. I try to maintain a command line environment that’s almost entirely dependent on MacPorts. Prior to ensuring this I ran into issues where software I’ve tried to install was using one utility or library provided natively by Mac OS X, while using some other utility or library I’ve installed separately, conflict due to differences and stop certain software from building properly upon install.

  3. Setting up Ubuntu for Rails App via Passenger

    These instructions apply to Ubuntu 11.04 (natty).

    Run the following to install Ruby, the Apache2 web server, Curl Development Headers with SSL Support.

    sudo apt-get update
    sudo apt-get install build-essential
    sudo apt-get install ruby ruby1.8-dev
    sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev libcurl4-openssl-dev

  4. Formtastic use of semantic_form_remote_for

    With the update to Formtastic version 2.0.0.rc1 the ‘semantic_remote_form_for’ method was removed and support was added to ‘remote_form_for’ used like this:

    <%= semantic_form_for @contact, :remote => true, :url => '/contact' do |f| %>

    This is to conform with the new Rails 3 update where form_remote_for is replaced with form_for with a remote hash value passed to it as an argument.

  5. Exporting Routes in Rails 3

    I’m currently upgrading a project I’m working on from Rails 2.3.8 to Rails 3.1. As part of this upgrade I need to test the entire application for issues, because we haven’t actually written any tests.

    To help with this, I’d like to export all the routes so that I can test them one by one, and keep track of what I’ve tested and fixed already.

    Typically I output the routes by using this command from the root of the Rails app:

    rake routes

  6. Using URL Helpers in Models or Rake Tasks

    If for some reason you need to use URL helpers which are based on the routes you’ve defined in Rails 3.1, simply add the following to the model method or rake task:

    include Appname::Application.routes.url_helpers

    Make sure you replace ‘Appname’ with the name of your app, which should be the same name as the root folder for your application. You can also obtain it from /config/application.rb where it is defined like so:

  7. Building a Query String from a Hash with Rails 3

    I have a model has a method that generates and stores a cached link to it’s own view for use in mailers. Under Rails 2 the method which generated this link created the beginning of the URL based on the owner of the object (this is a multi-domain system I’m working on), however it required that a hash of parameters be included in the link.

    Under Rails 2 the ‘options’ hash would be passed to build_query_string inside of my method like so:

    params =

  8. Rails 3 Autoloading with Namespaced Models

    I’m working through an upgrade from Rails 2.3.8 to Rails 3.1, and a set of name spaced models that I setup are giving errors when I run a certain Rake task that relies on them. I looked into the issue and it appears that I need to learn the way Rails 3 loads models.

    In /config/application.rb I’m using the following line to auto load all models from /app/models and any subdirectories.

    config.autoload_paths += Dir["#{config.root}/app/models/**/"]

    For this to work I found that I needed to understand how Rails 3 interprets the folder and filenames. Some models weren’t even registering as available, so I created folders for each class and put their files under each folder. This seemed to resolve some errors, but then I was receiving errors when I would try to instantiate a new object from one of the defined classes in the Rails console:

  9. Form Fields not Displaying with Formtastic

    The Rails project I’m currently working on uses Formtastic, a Rails form builder plugin. The projects description says “Formtastic is a Rails FormBuilder DSL (with some other goodies) to make it far easier to create beautiful, semantically rich, syntactically awesome, readily stylable and wonderfully accessible HTML forms in your Rails applications.” I wasn’t sure what DSL means, but found in the projects wiki on the About page that it stands for Domain Specific Language.

    So I’m currently upgrading from Rails 2.3.8 to Rails 3.1, and I found that the form fields were not showing for the pages using the Formtastic semantic_form_for code blocks. I updated my own code so that the equal sign is included after the opening Ruby code tag in the views such as:

    <%= semantic_form_for @product do |f| %>

    … instead of …

    <% semantic_form_for @product do |f| %>

  10. Adding Event Listeners to Google-Maps-for-Rails Markers

    I’m currently working on a Ruby on Rails project that was setup under Rails 2, and we’re upgrading it to Rails 3 via a separate branch.

    We were using a gem called Eschaton to provide Google Maps on certain pages of the website, but it appears that Eschaton is abandoned and actually going to be deleted on October 31, 2011. Because of this I forked the project under my own Github account.

    After looking around for a suitable replacement we decided on Google-Maps-for-Rails, version (1.3.0). Previously with Eschaton we had jQuery code associated with event listeners that were triggered when the markers on the map are selected. When selected the items being plotted on the map, which are displayed to the left of the map, were highlighted using CSS after being clicked on, and page also scrolled down to the item selected on the map. To reproduce this we need to tie events to the markers using Google Maps for Rails (gmaps4rails).