# No Method Error - Active Record

**URL:** <https://www.ruby-forum.com/t/no-method-error-active-record/172843>\
**Category:** Rails\
**Created:** [July 28, 2009, 8:45pm UTC](https://www.ruby-forum.com/t/no-method-error-active-record/172843 "2009-07-28T20:45:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![intellections](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7cd45c/32.png) [@intellections](https://www.ruby-forum.com/u/intellections)\
**Post date:** [July 28, 2009, 8:45pm UTC](https://www.ruby-forum.com/t/no-method-error-active-record/172843/1 "2009-07-28T20:45:10Z")

</div>

I posted this in the Ruby forum but I was told it would be more at home  
here.

I’m very new to ruby so for all I know this could be ridiculously easy.  
Thank you in advance for any and all suggestions!

Here is the error:  
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active\_record/base.rb:2962:in  
`log_protected_attribute_removal': undefined method`debug’ for  
nil:NilClass (NoMethodError)  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active\_record/base.rb:2946:in  
`remove_attributes_protected_from_mass_assignment' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2739:in`attributes=’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active\_record/base.rb:2439:in  
`initialize' from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:726:in`new’  
from  
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active\_record/base.rb:726:in  
`create' from ./read_categories.rb:42 from /home/emergenc/RubyGems/gems/parseexcel-0.5.2/lib/parseexcel/worksheet.rb:143:in`each’  
from  
/home/emergenc/RubyGems/gems/parseexcel-0.5.2/lib/parseexcel/worksheet.rb:143:in  
`each’  
from ./read\_categories.rb:41

When I traced it in the code this error is what would be displayed if  
that debug undefined method error wasn’t there:  
“WARNING: Can’t mass-assign these protected attributes:  
#{attributes.join(’, ')}”

Here is the relevant code:  
#!/usr/bin/ruby  
ENV[‘GEM\_PATH’] = ‘/home/emergenc/RubyGems:/usr/lib/ruby/gems/1.8’  
require ‘rubygems’;  
require ‘parseexcel’  
require ‘net/ftp’  
require ‘activerecord’  
require ‘csv’

#Make Database Connection  
ActiveRecord::Base.establish\_connection(:adapter=\>“mysql”,:host=\>“localhost”,:username=\>“xxxxxxx”,:password=\>“xxxxx”,:database=\>“e\_shop”)

class Category \< ActiveRecord::Base  
end  
class Subcategory \< ActiveRecord::Base  
end  
class Item \< ActiveRecord::Base  
end

#Open the excel file  
cat\_worksheet =  
Spreadsheet::ParseExcel.parse("/home/emergenc/DataFiles/categories.xls").worksheet(0)  
subcat\_worksheet =  
Spreadsheet::ParseExcel.parse("/home/emergenc/DataFiles/subcategories.xls").worksheet(0)

#Delete Currently Existing Data  
Category.connection.execute(“TRUNCATE TABLE categories”)  
Subcategory.connection.execute(“TRUNCATE TABLE subcategories”)  
Item.connection.execute(“TRUNCATE TABLE items”)

(I CUT OUT IRRELEVANT CODE, LINE 39 Starts with #LOAD, LINE 40 starts  
with cat\_w…, and LINE 41 starts with Category.create to map from the  
error message)  
#Load Category Data  
cat\_worksheet.each(1) do |row|  
Category.create(:description=\>(row.at(1).to\_s(‘latin1’)).split(/\s+/).each{  
|word| word.capitalize! }.join(’ ‘), :id =\> row.at(0).to\_s(‘latin1’))  
unless row.nil?  
end  
Category.connection.execute("UPDATE categories c SET grouping\_id =  
(SELECT max(id) FROM groupings g where lower(c.description) like  
concat(’%’,lower(g.description),’%’))")  
Category.connection.execute("UPDATE categories c SET grouping\_id =  
(SELECT grouping\_id FROM grouping\_overrides g where c.description =  
g.category\_desc) WHERE grouping\_id is nul$  
Category.connection.execute(“UPDATE categories c SET grouping\_id =  
(SELECT id FROM groupings g where g.description = ‘Other Items’) where  
grouping\_id is null”)

---

<div class="post-metadata">

**Author:** ![intellections](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/7cd45c/32.png) [@intellections](https://www.ruby-forum.com/u/intellections)\
**Post date:** [July 28, 2009, 8:57pm UTC](https://www.ruby-forum.com/t/no-method-error-active-record/172843/2 "2009-07-28T20:57:21Z")

</div>

For anyone searching for a solution to this:

Add ActiveRecord::Base.logger = Logger.new("debug.log) before the  
database connection.

(Care of halogenandtoast on IRC)
