Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined method `bytesize' for #<Hash>

Tags:

I'd like to store and update blogger labels to datastore in GAE. When I run that code, I get this error:

javax.servlet.ServletContext log: Application Error /base/data/home/apps/yet-another-problem/1.334886515480009498/WEB-INF/gems/gems/sinatra-0.9.2/lib/sinatra/base.rb:45:in `each': undefined method `bytesize' for #<Hash:0x86684c> (NoMethodError) 

The Code

class Labels    class LabelData     include Bumble     ds :blog_element_labels    end    def update     response = URLFetch.get($label_url)     result = response.to_s     result_headless = result.gsub("listLabels(",'')     pure_result = result_headless.gsub(");",'')     json_to_yaml = YAML::load(pure_result)['entry']['category']      json_to_yaml.each do |label|     @label = LabelData.find(:blog_element_labels => label['term'])     @label = LabelData.create(:blog_element_labels => label['term']) if @label.nil?     end   end end 

and run by cron job does '/job'

get '/job' do   @labels = Labels.new   @labels.update end 

Where is the problem? Please teach me.

But when run cron job first time, label data was stored, even occur that error. Could not update data.

like image 750
tknv Avatar asked Jul 14 '09 05:07

tknv


1 Answers

I think your having the same problem that's been discussed here: error happens when I try "all" method in datamapper

In your case, Sinatra is trying to take the return value of @lavels.update and turn that into a string to display to the user.

Try this to see if it fixes the problem:

get '/job' do   @labels = Labels.new   @labels.update   "Labels Updated" end 

Your return value is now a string, so you shouldn't get the error.

like image 164
Luke Antins Avatar answered Oct 19 '22 16:10

Luke Antins