I'm creating a Sinatra app that takes an uploaded CSV file and puts its contents in a hash. When I reference this hash in my app.rb like so:
hash = extract_values(path_to_filename)
I keep getting this error message:
undefined method `bytesize' for Hash:0x007fc5e28f2b90 #object_id
file: utils.rb location: bytesize line: 335
I read somewhere that this is a Webrick issue. I switched to Thin, the error's the same.
My hash / CSV file is of very small size, so it can't be the issue.
I'm using ruby 1.9.3p374.
Thanks!
This looks like a duplicate of Undefined method `bytesize' for #<Hash>
Sinatra is expecting a string be returned (i.e. last line) of the route method; you can't just return a straight hash.
Solved:
1) pass the collection to the view:
get '/file/:filename' do
filename = params[:filename]
@rows = extract_values(testfile_path(filename))
haml :search_term
end
2) iterate over it in the view template (erb / haml):
%ul
- @rows.each do |hash|
%li
Id: #{hash[:id]}, Keyword: #{hash[:keyword]}, Searches: #{hash[:searches]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With