attributes: rails reserved variable :(

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 :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 :).

Advertisements

One response to “attributes: rails reserved variable :(

  1. Pingback: Rails gotchas (reserved attribute or method name) | Urubatan&#8217;s Weblog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

my tweets

October 2007
S S M T W T F
« Sep   Nov »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Flickr Photos

RSS my shared links on google reader

  • An error has occurred; the feed is probably down. Try again later.
%d bloggers like this: