views:

46

answers:

1

I have a couple of objects in a Rails app ("Ticket", and "Comment")

class Ticket < ActiveRecord::Base
  has_many    :attributes
  has_many    :comments
end

class Comment < ActiveRecord::Base
  belongs_to :ticket
  belongs_to :user
end

with the following schema:

create_table "comments", :force => true do |t|
  t.integer  "ticket_id"
  t.integer  "user_id"
  t.text     "content"
  t.datetime "created_at"
  t.datetime "updated_at"
end

create_table "tickets", :force => true do |t|
  t.integer  "site_id"  
  t.integer  "status"
  t.integer  "user_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

However, for some reason - whenever I do a @lead.comments I get a crash:

can't convert String into Integer

Any ideas? This is driving me nuts!

A: 

I think the line that's causing you pronlems is:

has_many :attributes

"attributes" is a special word in an Active Record. It refers to the values of the columns in the db.

If you try and override this with an association, then you will have problems. My suggestion is that you should not have a model called an "attribute" - call it something else, eg "properties", and the problems will go away.

Taryn East