# NoMethodError: undefined method \`\<=\>' for :zip:Symbol

**URL:** <https://www.ruby-forum.com/t/nomethoderror-undefined-method-for-symbol/186757>\
**Category:** Rails\
**Created:** [February 25, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-for-symbol/186757 "2008-02-25T20:26:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyleh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@kyleh](https://www.ruby-forum.com/u/kyleh)\
**Post date:** [February 25, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-for-symbol/186757/1 "2008-02-25T20:26:56Z")

</div>

Long time programmer, but I just started learning RoR last week. I am  
going through some examples in the book “Ruby on Rails: Up and  
Running”.

The example I am on had me add a table to the database that looks like  
so:  
CREATE TABLE people (  
`id` int(11) NOT NULL auto\_increment,  
`type` varchar(20) default NULL,  
`name` varchar(20) default NULL,  
`email` varchar(30) default NULL,  
`street_address` varchar(30) default NULL,  
`city` varchar(30) default NULL,  
`state` varchar(20) default NULL,  
`zip` int(5) default NULL,  
`camera` varchar(20) default NULL,  
PRIMARY KEY (`id`)  
)

In addition, I created the following two classes:

class Person \< ActiveRecord::Base  
composed\_of :address, :class\_name =\> “Address”,  
:mapping =\> [[:street\_address, :street\_address],  
[:city, :city],  
[:state, :state],  
[:zip, :zip]]  
end

class Address  
def initialize(street\_address, city, state, zip)  
@street\_address = street\_address  
@city = city  
@state = state  
@zip = zip  
end

attr\_reader :street\_address, :city, :state, :zip  
end

Finally, it had me run the following commands in Console:

> > elvis.name=Person.new  
> > elvis.name=Person.new  
> > NameError: undefined local variable or method `elvis’ for #\<Object:  
> > 0x284f9e8\>  
> > from (irb):1
> 
> > elvis=Person.new  
> > elvis=Person.new  
> > =\> #\<Person id: nil, type: nil, name: nil, email: nil, street\_address:  
> > nil, city: nil, state: nil, zip: nil, camera: nil\>
> 
> > elvis.name=“Elvis Presley”  
> > elvis.name=“Elvis Presley”  
> > =\> “Elvis Presley”
> 
> > elvis.email=“removed\_email\_address@domain.invalid”  
> > elvis.email=“removed\_email\_address@domain.invalid”  
> > =\> “removed\_email\_address@domain.invalid”
> 
> > address=Address.new(“3734 Elvis Presley Blvd”, “Memphis”, “Tennessee”, 38118)  
> > address=Address.new(“3734 Elvis Presley Blvd”, “Memphis”, “Tennessee”,

1. 

=\> #\<Address:0x3f3ce94 @street\_address=“3734 Elvis Presley Blvd”,  
@zip=38118, @state=“Tennessee”, @city=“Memphis”\>

> > elvis.address=address  
> > elvis.address=address  
> > =\> #\<Address:0x3f3ce94 @street\_address=“3734 Elvis Presley Blvd”,  
> > @zip=38118, @state=“Tennessee”, @city=“Memphis”\>
> 
> > elvis.save  
> > elvis.save

However, when I ran the latter-most command, “elvis.save” I received  
the following (abbreviated) error:

NoMethodError: undefined method `<=>' for :zip:Symbol from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/base.rb:2177:in`sort’  
from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/  
active\_record/base.rb:2177:in `attribute_names' from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/base.rb:2458:in`clone\_attributes’  
…

Why is the method ‘\<=\>’ being attempted on the zip field?

---

<div class="post-metadata">

**Author:** ![kyleh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a9a28c/32.png) [@kyleh](https://www.ruby-forum.com/u/kyleh)\
**Post date:** [February 26, 2008, 8:41am UTC](https://www.ruby-forum.com/t/nomethoderror-undefined-method-for-symbol/186757/2 "2008-02-26T08:41:26Z")

</div>

On 25 Feb 2008, at 19:26, removed\_email\_address@domain.invalid wrote:

> active\_record/base.rb:2458:in `clone\_attributes’  
> …
> 
> Why is the method ‘\<=\>’ being attempted on the zip field?

it’s not calling \<=\> on the zip field itself but on the mapping you’ve  
supplied, which is expected to contain strings

> :mapping =\> [%w(street\_address street\_address),  
> %w(city city),  
> %w(state state),  
> %w(zip zip)]  
> Should do the trick

Fred
