One of the much larger Rails applications I work on makes heavy use of caching for obvious reasons. In some locations the cache isn’t auto-expiring at the moment. After doing a deployment I needed to expire these sections manually via the console for my first time. I grabbed the name of the fragment from the view where it was being cached. - cache('all_category_judges') do ... I only knew one way to access the cache in the console and attempted clearing the cache fragment from there.

Continue reading

Today I was trying to generate a Rails 3.1.0 project (for testing purposes). I simply called rails new rollback which generated a rails 3.2.11 project and proceeded to change the gemfile version to 3.1.0. This resulted in numerous application errors. The simple solution was to generate the project with the Rails version 3.1.0. To do this call the gem with the version number as such: $ rails _3.1.0_ new rollback You also must already have this version of the gem installed on your system for it to work.

Continue reading

This week at the office I’ve been on a coding hiatus and just doing a lot of copy placement and markup. The client requested having a numbered list of categories separated by type headers. I added markup as such: %ul %li %h2 Video %ol %li Animation %li Documentary %li Music Video %li Narrative %li Poetry/Experimental %li Collaboration %li UNICEF Challenge %li %h2 Print %ol %li Photo Collection/Digital Story/Photo Essay %li Poster/Collage/Campaign Output:

Continue reading

I was writing a rake task to handle importing data from an older community system and needed to set a default value for anything that the old system didn’t have. I was using hashs and thought to myself “It would be sweet if hashs had defaults.” After a quick doc check I found out that hashs do infact support defaults. I encourage you to check out the Ruby Docs http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-default

Continue reading

In the apps I’ve been working on recently I decided to utilize rails built in authentication ‘has_secure_password’ which began shipping with Rails 3.1. Has_secure_password is simple to use and doesn’t bring in any extra bulk. With some of these projects I also decided to use MongoDB & Mongoid. When trying to use the has_secure_password method I got: undefined local variable or method `has_secure_password' for User:Class (NameError) Solution: You must include include ActiveModel::SecurePassword.

Continue reading

While working with the ActiveRecord method ‘new_record?’ and Transactions I ran into an odd issue after I had run a few objects through a Transaction. Although the transaction had rolled back and thus not saving the record, running ‘object_instance.new_record?’ resulted in a return of false as if the record had been saved to the database. I also found the same issue recorded here: http://squarewheel.wordpress.com/2008/06/11/new_record/ Here is example code where the error will happen.

Continue reading

While working with my new employer (in 2011) I noticed a minor but recurring issue in our application. We had been storing flash[:notice] messages in most of our actions but were not using that flash message anywhere. This was resulting in the flash message showing up at in-appropriate times. What I was unaware of was a slightly different call which is flash.now[:notice]. This results in the flash only having a lifespan of the through the next request.

Continue reading

Author's picture

Brian Pearce

Software Engineer, Endurance Cyclist,
Rubiest, and Rustacean

Software Engineer

Barcelona, Spain