No Method Error

K

Kyle Thomas

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")
 
J

Jason Lillywhite

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

Have you tried a very simple function where you parse a very small
spreadsheet dataset? Once that is working, build up from there?

You might find you have nil when you expected some value returned from
your spreadsheet. It will be a matter of finding the source of that
'nil'
 
B

Brian Candler

Kyle said:
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)

That means you are trying to call nil.debug

Just open the file and look at the source line:

logger.debug "WARNING: Can't mass-assign ... "

So logger is nil here.

You probably want something like:

ActiveRecord::Base.logger = Logger.new

or perhaps ActiveSupport::BufferedLogger.new("/path/to/log")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top