Blog - Page 1 of 1


Keep your controllers skinny
#Web development
Posted on

You'll hear it lots, fat models/skinny controllers but I was working on a project recently where my controller code was putting on a bit of weight!

The requirement was that when a post was saved with a url, a gem I had installed called LinkThumbnailer would visit that url to find the first image on the page and return the image url.

Read more
DRY model code
#Web development
Posted on

I had a case in my postit application where I needed to add voting for both comments and posts. This required some code in my models for Post and Comment to count the votes:

has_many :votes, as: :voteable

def total_votes
  up_votes - down_votes
end

def up_votes
  self.votes.where(vote: true).size
end

def down_votes
  self.votes.where(vote: false).size
end
Read more
URL and HTTP Reminder
#Web development
Posted on

This is just a quick reminder on the make up of a URL and basic details of a HTTP request/response cycle.

Read more