title: Virtual attributes Rails - Unknown Attribute Error
body: <p>I'm making a Rails 4 application. Each <code>incident</code> belongs to a <code>user</code>. Each incident <code>has many events</code>. I want that I can create an Incident with <code>current_user.incidents.new</code> and pass it an attribute <code>message</code> which exists in the Event model. On creation, I wish to create a new event with the said <code>message</code>. </p>
  
  <p>Here's my Incident model. </p>
  
  <pre><code>class Incident &lt; ActiveRecord::Base
    # The 'incident' model.
    # Incidents are created by Users (belongs_to :user)
    # Incidents may be public or private.
    # Incidents have many events (identified, fixing, etc.)
  
    belongs_to :user
    has_many :events
    validates :name, presence: true, length: {maximum: 256}
    validates_presence_of :component
    validates_presence_of :public
    validates_presence_of :user_id
  
    attr_accessor :message
    validates_associated :message, presence: true
  
    def message
      Event.find_by_incident_id(self.id).message
    end
  
    def message=(value)
      self.events.new(message: value, status: self.status)
    end
  
    private
      def incident_params
        params.require(:incident).permit(:name, :status, :user_id, :message)
      end
  
  end
  </code></pre>
  
  <p>But, when I run <code>@i = Incident.new(message: 'something')</code>, I get <code>ActiveRecord::UnknownAttributeError: unknown attribute 'message' for Incident.</code></p>
  
  <p>Please help me figure this out.</p>