rubycoloredglasses


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


  1. Invalid Gemspec Error Regarding Invalid Date Format

    I installed factory_girl (2.6.0) for a project I am working on recently, and all of a sudden I started getting errors with RubyGems when I would try to run a rake task, such as:

    Invalid gemspec in
    [/opt/local/lib/ruby/gems/1.8/specifications/capistrano-2.11.2.gemspec]:
    invalid date format in specification: "2012-02-22 00:00:00.000000000Z"
    
    Invalid gemspec in
    [/opt/local/lib/ruby/gems/1.8/specifications/capistrano-2.9.0.gemspec]:
    invalid date format in specification: "2011-09-24 00:00:00.000000000Z"
    

    I went through the long process of uninstalling all my gems, running an update on RubyGems using ‘gem update –system’ and then reinstalling them again via ‘bundle install’. Still the gems were uninstalled, yet the specification errors were still occurring.


  2. Deleting Git Branches in Remote Repository

    I had recently used a branch to handle all the modifications I was making to a system for a Rails 3.1 upgrade from Rails 2.4.3. After I merged my changes back into the master branch, I deleted the ‘rails3’ branch locally, but it still remained on the remote server.

    I found that ‘git push origin :branch_name’ will delete the repository from the remote server if the branch has been removed locally.

    $ git push origin :rails3
    To git@example.com:myrepo.git
     - [deleted]         rails3
    

  3. Rails 3 on WHM / cPanel VPS Server

    cPanel is working towards making Rails 3 applications run natively with Passenger, setup via the cPanel interface. I’m not really sure if this will be ideal, as most organizations deploy their apps to the server using Capistrano, not uploading via FTP or something.

    I’ve been hosting a number of PHP driven sites, including this blog, from a shared hosting service for quite a while now. Shared hosting is fine for personal websites or even small businesses with 4-5 page brochure style websites that do not receive lots of traffic, but they’re not fine if slow performance or intermittent downtime causes you to loose business (or even the respect of your visitors). In such cases I recommend a VPS, because you control who you’re hosting and thus can ensure optimal uptime and performance. I highly recommend Linode as a VPS provider.


  4. Configuring Rails 3.1.3 under Sub-URI

    In setting up a new Rails app recently I was told that it needed to be served under the sub-URI of ‘/info’. I hadn’t done this before with a Rails app, and I expected that it could be tricky.

    I checked online to see how this is done and found references to the ‘relative_url_root’ setting, but then shortly found that this has been deprecated.

    I’m using Phusion Passenger with Apache 2, so I inserted the following configuration into my VirtualHost entry for the site.


  5. Custom Rake Tasks Not Loading

    I recently went to create a new Rake task under /lib/tasks in a Rails application I’m working on. I didn’t understand why the rake tasks weren’t showing when I would run rake -T from the command line.

    When I’d try to run the task itself I would get a ‘Don’t know how to build task’ error.

    I just realized that I was naming my task file with the ‘.rb’ extension, and not ‘.rake’. Doh!


  6. Troubleshooting ActiveResource Requests

    I’m currently working on an app which integrates with the HighRise API using the Highrise Ruby wrapper gem. The classes defined by the gem rely on ActiveResource, the Ruby library included with Rails for interfacing with RESTful resources like the HighRise API.

    Sometimes I’m not sure if the requests being made via the commands I’m using are making the right calls on the HighRise API.

    I found this thread on StackOverflow: How do I view the HTTP response to an ActiveResource request?. The solution I found helpful was this one on overriding ActiveResource::Connection so that it outputs the debug output. This worked for me even with Rails 3.1.


  7. Example Rake Task

    Here is example rake task code which you can use and modify the next time you’re setting up new Rake tasks for a Rails app from scratch. The example includes the syntax for setting the default task, running multiple tasks in order, and a task which includes multiple arguments. This coding syntax works with Rails 3.1.

    # /lib/tasks/mytask.rake
    namespace :mytask do
      task :default => 'mytask:full_run'
    
      desc "run all tasks in proper order"
      task :full_run => [:example_task_one, :example_task_two] do
        puts "All tasks ran and completed at #{Time.now}"
      end
    
      desc "example task without arguments"
      task :example_task_one => :environment do
        # task code goes here
        puts "Example Task One completed"
      end
    
      desc "example task with arguments"
    
      task :example_task_two, [:arg1, :arg2] => :environment do |t, args|
        # if no arguments, display docs
        if args.count == 0
          puts ''
          puts "rake mytask:example_task[arg1,arg2]"
          puts "arg1: description of first argument"
          puts "arg2: description of second argument"
          puts ''
          puts "example:"
          puts "rake mytask:example_task[123,'456']"
          puts ''
        else
          # task code goes here
          puts "Running task with arg1: #{args.arg1}, and arg2: #{args.arg2}"
          puts "Example Task Two completed"
        end
    
      end
    end
    

    Special thanks to Jason Seifer for his Rake Tutorial which made this possible.


  8. Adding a New User in Ubuntu

    Adding User

    When setting up a new website manually on an Ubuntu server you need to establish a user account with a home directory, and Bash shell access to the server.

    useradd -m testuser -s /bin/bash
    

    After creating the account you’ll want to assign a password for the account.

    passwd testuser
    

  9. Resolving issues with Namespaced Models in Rails 3.1.0

    I recently was tasked with upgrading an application from Rails 2.3.8 to Rails

    1. I choose to upgrade it to Rails 3.1, because why upgrade once and then have to do it again later.

    After upgrading and testing many points of the system locally, I was ready to push the upgraded application to the production server. After pushing it out I started to notice that a certain rake task was failing to run via a cronjob I had setup. This rake task worked with certain non-ActiveRecord models, which I had setup with a hierarchy which utilized inheritance and namespacing.

    Under Rails 2.3.8 I had a file, /app/models/rets_map/rets_map_base.rb. The error I was receiving from the rake task involved some sort of issue loading the class from this file.


  10. 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:

    upload.errors.inspect:
    
    #["/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=#>