Loading... Cancel

attributes: rails reserved variable :( R

October 20th, 2007

yesterday, i had a pretty rough working day, i was stucked (along with my team) with some simple joining. we had the following models -

Attribute
———–
class Attribute < AR:B
belongs_to :category
end

class AttributeValue < AR:B
belongs_to :item
belongs_to :attribute
end

class Item < AR:B
has_many :attribute_values
has_many :attributes, :through => :attribute_values
end

rails wasn’t giving much better error message, instead it was saying, “invalid type, String to Integer..”, so far i understood ActiveRecord stuff was trying to cast a string to integer.

we even didn’t know which field was doing this stupidity and so on…
so later we dug down to the rails scripts, we added few debug messages. we found “[]” was invoked to set “id” string value.

anyway, after digging more into to this issue, today i gave another try after 7 hours of nice sleep. it was about rails reserve words.

though i heard something from the rails community, but i was expecting some message or  errors which explain this issue.

anyway, i always like fail first approach. if something is not possible it should fail first. at least it should return a meaningful exception.

i believe Active Record should be patched with more clear warning or exception, if any reserved word is used for model or controller or others it should let us inform :) .

Total 1 response found

Close