I have a simple Rails 3 model, with an attr_accessor that doesn’t have a field in the database, and I need to set it up using fixtures, because of my initialization setup.
But when I try it, I get an error about the unknown column.
Is there another way to do this?
My model:
class Timeslot < ActiveRecord::Base
attr_accessor :interval
after_initialize :init
def init
self.interval ||= 15
self.start_time ||= Time.local(0, 1, 1)
self.end_time = self.start_time.advance :minutes => self.interval
end
end
Fixtures add data directly into the database. If you want to pass data to a model instead, consider using factories (Factory Girl is a good library).
You may already have a big investment in fixtures, but factories are well worth a look.