Archive for the ‘format’ Category

Getting around format in Rails and Ruby

Tuesday, November 21st, 2006

In Rails you can’t have a column named format in a table as it is a reserved Ruby word. Fair enough. But how then can you handle a database that has a column named that in Rails without using views?

It turns out to be surprisingly logical; modify your Rails model with two new methods. You need a getter and setter so for example:

def dialect
  return self.format
end

def dialect=(value)
  self.format = value
end

Now my model has a method of dialect which gets and sets to format in the database.