I have a Person model. When a new Person is created, I want to set a random_variable in the controller and pass it as part of the @person object. I have tried
Model
attr_accessor :random_variable
Controller:
def create
@person = Person.new(params[:person])
@person.random_variable = 'A Random string'
@person.save
end
Unfortunately, if I try and access self.random_variable in the model, this doesn't work (I get nil).
Can someone explain why this doesn't work, and how to go about doing it? (and yes, I know this doesn't really hold with MVC convention, but the only other way of doing what I need is a very heavy non-dry controller)