fresh - January


Photo of footbridge on river Itchen

Photo of an old footbridge on the river Itchen, Hampshire, UK.

The website has received a makeover thanks to a theme called Flatty so it is a bit sweeter on the eyes. In the past I have tried to hand craft a design straight from Bootstrap but in order to spend time building features I have utilised a pre-existing theme and fixed/tweaked a few things.

The app now has a sign up page in the longer term plan to provide more features to regular users. After spending less time messing with CSS I can start to build the moment explore views, providing a nicer way to search and explore existing moments. web application

Capture this moment in time, record the events of now. Save this moment forever.

Gem alert: Virtus

A Rubygem I have recently started appreciating is Virtus - a Ruby Object Mapper that allows you to define attributes by type.

A great use of this in Rails apps is to separate validations out from your ActiveRecord model into a form object, moving the validations away from the model allows you to validate the model in different situations and makes the models cleaner.

Here is an example I have used recently in the haz-commitz project for taking an input from a form, validating and returning the components we’re interesting in.

class NewRepositoryForm
  extend ActiveModel::Naming

  include Virtus.model
  include ActiveModel::Validations
  include ActiveModel::Conversion

  attribute :path, String

  validates :path, presence: true
  validates_format_of :path, with: /\//i

  def model_name

  def persisted?

  def name

  def owner

Now the model just represents your domain concept and persistence, this form object is a nice, clean way to validate the data before hitting the model. By extending ActiveModel::Naming we can use Rails path helpers and by including ActiveModel::Validations we can use sweet validations and call valid?. Nice.