Ruby on Rails

Debugging asset compilation errors

Using bundle show to debug undefined method 'directory?' for nil:NilClass while compiling rails assets

Thomas V.

2 minute read

While trying to deploy a new rails app to production I came across this undefined method ‘directory?’ error during asset compilation: ** Execute assets:precompile:all ** Invoke assets:precompile:primary (first_time) ** Invoke assets:environment (first_time) ** Execute assets:environment ** Invoke environment (first_time) ** Execute environment ** Invoke tmp:cache:clear (first_time) ** Execute tmp:cache:clear ** Execute assets:precompile:primary rake aborted! undefined method directory?' for nil:NilClass /srv/www/rails/arthouse/shared/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:189:inblock in each_entry’ /srv/www/rails/arthouse/shared/bundle/ruby/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:185:in `each’ This problem was only showing up in production, and there were a number of symlinks I thought may have been the culprit, unfortunately the error output was less than helpful.

Automatically start Rails applications after reboot

Create a simple shell script that restarts your Ruby on Rails application's unicorn instance.

Thomas V.

1 minute read

Convert the deploy:start functionality of your existing capistrano deploy recipe to a shell script: # /var/www/app/start.sh cd /var/www/app/current && (PATH=$HOME/.rbenv/shims:$HOME/.rbenv/bin: RAILS_ENV=production /usr/bin/env bundle exec unicorn -c /var/www/app/current/config/unicorn.rb -E production -D) Make it executable: chmod u+x /var/www/app/start.sh Add it to /etc/rc.local (be sure to replace app with whatever your applications user is): #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error.

Thomas V.

2 minute read

About a month ago I cut my hours back from full time to part time, and ever since I’ve been working on building a product that is yet to launch called OrderDeck. One of OrderDeck’s primary functions is that a user must be able to upload file attachments to custom orders and conversations. When a file is uploaded the user is notified and they can either preview or download the file.