# syntax error, unexpected tINTEGER, expecting $end

**URL:** <https://discuss.rubyonrails.org/t/syntax-error-unexpected-tinteger-expecting-end/43690>\
**Category:** rubyonrails-talk\
**Created:** [June 23, 2009, 8:52am UTC](https://discuss.rubyonrails.org/t/syntax-error-unexpected-tinteger-expecting-end/43690 "2009-06-23T08:52:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ease\_Bus](https://avatars.discourse-cdn.com/v4/letter/e/d9b06d/32.png) [@Ease\_Bus](https://discuss.rubyonrails.org/u/Ease_Bus)\
**Post date:** [June 23, 2009, 8:52am UTC](https://discuss.rubyonrails.org/t/syntax-error-unexpected-tinteger-expecting-end/43690/1 "2009-06-23T08:52:06Z")

</div>

Please help me solve the following error message:

&nbsp;&nbsp;&nbsp;&nbsp;syntax error, unexpected tINTEGER, expecting $end

I have this model:

Code:

&nbsp;&nbsp;&nbsp;1. class GeoDatum \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;2. end

The database contains the table geo\_data, which contains the zip\_code column, filled with zip codes. I get the above error when searching for a zip code and the zip code exists in the table. Here is the console output:

&nbsp;&nbsp;&nbsp;&nbsp;\>\> GeoDatum.find\_by\_zip\_code(95035) &nbsp;&nbsp;&nbsp;&nbsp;SyntaxError: compile error &nbsp;&nbsp;&nbsp;&nbsp;/opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active\_record/base.rb:2203: syntax error, unexpected tINTEGER, expecting $end &nbsp;&nbsp;&nbsp;&nbsp;"95036 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active\_record/base.rb:2203:in `compute_type' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/ active_support/core_ext/kernel/reporting.rb:11:in `silence\_warnings' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active\_record/base.rb:2200:in `compute_type' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/base.rb:1640:in `instantiate' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active\_record/base.rb:661:in `find_by_sql' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/base.rb:661:in `collect!' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active\_record/base.rb:661:in `find_by_sql' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/base.rb:1553:in `find\_every' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active\_record/base.rb:1510:in `find_initial' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active_record/base.rb:613:in `find' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/ active\_record/base.rb:1905:in `find\_by\_zip\_code' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):3

I notice that the zip code 95035 is mysteriously incremented by one to become 95036 in the error message. Interestingly, when the zip code does not exist, no error is produced:

&nbsp;&nbsp;&nbsp;&nbsp;\>\> GeoDatum.find\_by\_zip\_code(11111) &nbsp;&nbsp;&nbsp;&nbsp;=\> nil &nbsp;&nbsp;&nbsp;&nbsp;\>\>

I am following the examples in "RailsSpace" by Hartl. I am using Ruby 1.8.7 and Rails 2.3.2. Not sure if this is a Ruby bug. See [http://redmine.ruby-lang.org/issues/show/386](http://redmine.ruby-lang.org/issues/show/386).

Below is the code that creates the geo\_data table. db:migrate went fine. Please help. Thanks.

Code

&nbsp;&nbsp;&nbsp;1. class CreateGeoData \< ActiveRecord::Migration &nbsp;&nbsp;&nbsp;2. def self.up &nbsp;&nbsp;&nbsp;3. create\_table :geo\_data do |t| &nbsp;&nbsp;&nbsp;4. t.column :zip\_code, :string &nbsp;&nbsp;&nbsp;5. t.column :latitude, :float &nbsp;&nbsp;&nbsp;6. t.column :longitude, :float &nbsp;&nbsp;&nbsp;7. t.column :city, :string &nbsp;&nbsp;&nbsp;8. t.column :state, :string &nbsp;&nbsp;&nbsp;9. t.column :county, :string &nbsp;&nbsp;10. t.column :type, :string &nbsp;&nbsp;11. end &nbsp;&nbsp;12. add\_index "geo\_data", ["zip\_code"], :name =\> "zip\_code\_optimization" &nbsp;&nbsp;13. &nbsp;&nbsp;14. csv\_file = "#{RAILS\_ROOT}/db/migrate/geo\_data.csv" &nbsp;&nbsp;15. fields = '(zip\_code, latitude, longitude, city, state, county, type)' &nbsp;&nbsp;16. &nbsp;&nbsp;17. # execute "LOAD DATA INFILE '#{csv\_file}' INTO TABLE geo\_data FIELDS " + &nbsp;&nbsp;18. # "TERMINATED BY ',' OPTIONALLY ENCLOSED BY \"\"\"\" " + &nbsp;&nbsp;19. # "LINES TERMINATED BY '\n' " + fields &nbsp;&nbsp;20. &nbsp;&nbsp;21. execute "LOAD DATA LOCAL INFILE '#{csv\_file}' INTO TABLE geo\_data FIELDS " + &nbsp;&nbsp;22. "TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' " + &nbsp;&nbsp;23. "LINES TERMINATED BY '\n' " + fields &nbsp;&nbsp;24. &nbsp;&nbsp;25. end &nbsp;&nbsp;26. &nbsp;&nbsp;27. def self.down &nbsp;&nbsp;28. drop\_table :geo\_data &nbsp;&nbsp;29. end &nbsp;&nbsp;30. end

---

<div class="post-metadata">

**Author:** ![hassan](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/hassan/32/714_2.png) [@hassan](https://discuss.rubyonrails.org/u/hassan)\
**Post date:** [June 23, 2009, 2:05pm UTC](https://discuss.rubyonrails.org/t/syntax-error-unexpected-tinteger-expecting-end/43690/2 "2009-06-23T14:05:26Z")

</div>

You might want to try this passing a string as an argument, as you've defined the column in your table 🙂

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [June 23, 2009, 3:23pm UTC](https://discuss.rubyonrails.org/t/syntax-error-unexpected-tinteger-expecting-end/43690/3 "2009-06-23T15:23:17Z")

</div>

> Please help me solve the following error message:
> 
> ```
> syntax error, unexpected tINTEGER, expecting $end
> 
> ```

Looks like you have a type column (which activerecord uses for single table inheritance) but you're actually storing data (such as 95036) in that column You can set which column AR uses for this with set\_inheritance\_column Fred
