Rails weirdness

Hi All

I have two “little” issues with my rails app that I am hopping
somebody could shed some light on. Here is the first one:

Two models, a and b, both have a description attribute (varchar(255))

In a function that assigns each attribute from one model to the other,
this statement fails with NoMethodError: description

a.description = b.description

yet the following code works just fine:

warn a.description
warn b.description
s = b.description
a.description = s

I just don’t get it why direct assignment fails…

The second issue has to do with model pluralization. Two Models: Event
and EventCategory when declared like this:

class Event < ActiveRecord::Base
has_many :EventCategories, :dependent => :destroy
end

class EventCategory < ActiveRecord::Base
belongs_to :Event
end

everything but destroying an event works. Meaning: I can create new
events, categories, enumarate through eventcategories by using
event.EventCategories syntax etc. The ONLY thing that throws up is a
call to event.destroy. The actual error is constant missing
event_categories.

However, defined like this (notice the has_many), everything works just
fine:

class Event < ActiveRecord::Base
has_many :event_categories, :dependent => :destroy
end

class EventCategory < ActiveRecord::Base
belongs_to :Event
end

Thanks

Rafael


http://www.bdcsoftware.com" - Automotive CRM

Thanks for the response. The first issue stopped happening soon after.
I don’t know what fixed it, but it might have been server reboot or
maybe it was a corrupted file (Uedid did prompt me to convert the file
to DOS several times). Anyhow, it works now.

Thanks

Raf

Hi Rafael,

On Sep 1, 2006, at 11:16 AM, Rafael S. wrote:

I just don’t get it why direct assignment fails…
Me neither. Everything spelled correctly and all that jazz?

has_many :event_categories, :dependent => :destroy
end

class EventCategory < ActiveRecord::Base
belongs_to :Event
end

Idiomatically, the first argument to associations like has_many and
belongs_to is a symbol from which Rails can infer the class name.
You’re “getting lucky” with the belongs_to :Event. You might
consider switching to belongs_to :event.

If Rails can’t infer the class name, you can supply it with :class_name