Category Archives: Configuration

Could Not Parse Yaml, Why!?

Yaml config files are a great way to store static data in your rails application. But there’s a little caveat I experienced today. Observe the following yaml file:

dog:
  poodle  
  husky  
  "golden retriever"

Looks fine, right? Now let’s assume you’ve named this yaml file dog.yml and it lives in your application’s config directory. You’d figure you could access the data by doing something like the following:

config=YAML.load_file('dog.yml')
puts config (yields the hash {"dog" => { "poodle", "husky", "golden retriever" } }

But for whatever reason, you are getting an error (couldn’t parse YAML at line x column x). You suspected that “golden retriever” might be a problem due to the space, but you’ve already quoted it, so no, it can’t be the problem.

Continue reading

Tagged

Auto Generate Factories for your Models

My good friend and colleague DS filled me in on a little trick that I’d like to share. When testing, it’s a good idea to have factories written for each model. Now, if your model is already created, you’ll have to spin up that factory manually. But how about ensuring your factories are created with each new model you generate?

Enters this nifty bit of code you can add to your config/application.rb file, within the Application class:

Continue reading

Critical Rails Security Issue

In January 2013, I was informed from a colleague about a severely critical security hole in nearly all Ruby on Rails versions. Although I’d read about the issue a couple weeks prior, I didn’t think I had to immediately worry about making the necessary upgrades to the patched versions, because all the Rails applications I was currently working on were still only in development modes, and running on local workstations under localhost. But then my colleague sent me a link to the following article (if you develop Rails applications, please read it):

http://www.kalzumeus.com/2013/01/31/what-the-rails-security-issue-means-for-your-startup/

Hopefully, you noticed from the article that even development applications running under localhost are vulnerable to this security breach. Continue reading

Tagged , ,

Vagrant Virtual Machine with Puppet for Rails

When I first started trying to learn Ruby on Rails, I noticed that there seemed to be a lot of steps, apt-gets, and other hoops and obstacles I had to tackle prior to getting my first “rails server” command to successfully fire up localhost:3000 with my rails application. I remember thinking to myself, if this is how hard it is to set up a workstation to run rails, then I’m not too sure it’s going to be all that pleasant to work with.

In particular, I realized that in a team setting, having to configure multiple workstations for each developer would be less than awesome. Yuck!

Enter VirtualBox and Vagrant. VirtualBox is a free Oracle product that allows developers to add virtual machine instances to their local operating system install. Vagrant is essentially a way to download an instance of an operating system, such as Precise32, and fire up a VirtualBox virtual machine on the fly in accordance to a specified config file.

Continue reading

Tagged , , ,