I'm having a bit of an issue getting two Users to belong_to the same model (Ticket).
In the bug tracker I'm building, a Ticket is a single task item that needs to be done to a Project. It has two Users attached to it, Ticket.raised_by and Ticket.assigned_to. The creating user
The problem is I consistently get an ActiveRecord::AssociationTypeMismatch
exception thrown on the Tickets#create
action, with an error message that looks kinda like
User(#81485590) expected, got String(#68375030)
Here's the code for Ticket.rb
:
# Table name: tickets
#
# id :integer not null, primary key
# title :string(255)
# description :text
# status :string(255) default("open")
# priority :boolean default(FALSE)
# project_id :integer
# raised_by_id :integer default(0)
# assigned_to_id :integer default(0)
# created_at :datetime
# updated_at :datetime
class Ticket < ActiveRecord::Base
validates :title, :presence => true
validates :status, :presence => true
belongs_to :project
belongs_to :raised_by, :foreign_key => 'raised_by_id', :class_name => 'User'
belongs_to :assigned_to, :foreign_key => 'assigned_to_id', :class_name => 'User'
before_create do
self.raised_by = current_user
end
state_machine :status, :initial => 'open' do
# when a ticket is "claimed" by a developer
event :work do
transition any => :working_on
end
# posted the solved ticket to the dev server (or VM)
event :post do
transition any => :posted
end
# ticket is under review by another developer
event :review do
transition any => :reviewed
end
# review is completed and confirmed. only reviewed or flagged tasks can be completed.
event :complete do
transition [:review, :flagged] => :completed
end
# occurs when the project is completed
event :close do
transition any => :closed
end
# Special treatment for administrators. Sends them a Message detailing the flagged issue.
event :flagged do
transition any => :flagged
end
end
end