HTML5: Data Attributes

HTML5 data attributes are a great alternative to classes and rel for storing data in an html tag. Creating a Custom Attribute Data attributes can be placed inside any type of tag and needs to follow the format of data-[desired_attribute]=”[value]” requiring at least one character following the dash.  Let’s look at an example: Let’s say you...
Read More

Test Driven Development (TDD) – Part 2 – Integration Testing

Now that your RSpec environment is all set up, it’s time to start writing some actual tests.  Let’s start with integrations tests, which tests how different components (models, controllers etc.) interact with one another. Create the Integration Folder To start, make future you and any team members really happy by creating an integration folder, within...
Read More

Parsing HTML with Nokogiri

Parsing with Nokogiri is a breeze, especially if you’re super familiar with CSS selectors and you’re good at traversing the DOM. 1. First, you need to install the Nokogiri gem: gem install nokogiri   If you are parsing something that lives remotely, you might want to include the open-uri module, which will make it even...
Read More

Polymorphism in 6 steps

A slightly advanced association in ActiveRecord is called polymorphic association. This usually happens when a model can belong to more than one model, even if it behaves the same way, but it’s easier to understand with an example. Suppose you have a blog that has articles, photos, and events. You want to add comments on...
Read More

Four rules for developers

… according to Sandi Metz, author of POODR. She mentioned these in a Ruby Rougues podcast and I thought they were interesting! 1. Classes can be no longer than one hundred lines of code. 2. Methods can be no longer than five lines of code. 3. Pass no more than four parameters into a method...
Read More