what could be causing this rails ioerror closed stream?
I think I've figured it out, at least I think I do ( the client just keeps on uploading now, error-free ) .
After you read data from a file that you upload, you should also CLOSE it. Who would have thought? :P
IOError (closed stream) on ActiveStorage::Attached::One#attach (Rails 6)
Okay, I found the answer. In rails 6 you have to open the tempfile again, when attaching, like this:
io: File.open(tempfile.path),
Hope this helps anyone with the same issue.
Capybara Poltergeist IOError: closed stream
The solution that worked best was to initiate a new Capybara session like this:
session = Capybara::Session.new(:poltergeist, Rails.application)
session.visit(...)
session.driver.quit
For my program I encapsulated it in a WebScraper module like this:
module WebScraper
attr_accessor :session
delegate :visit, :save_screenshot, to: :session
def start_session
@session ||= Capybara::Session.new(:poltergeist, Rails.application)
end
def end_session
@session.driver.quit
@session = nil
end
end
Uploading files to S3 using paperclip, IOError (closed stream) error
It looks like this is caused by a race condition between the ruby garbage collector and Tempfile.
Someone developed a patch for rails projects here: https://github.com/jwinky/ruby_tempfile_ioerror
Ruby gets stream closed stream IO error
I am on a different system so I cannot check your code. Anyway I suggest using File.foreach
:
File.foreach("packages_list.txt") do |line|
package_id = line.split[0].to_i
package = line.split[1]
dependencies = ""
url = BASE_URL + package
if package_id >= last_package
doc = Nokogiri::HTML(open(url))
doc.css(".uldep a").each do |dependency|
dependencies << dependency.text + ","
end
dependencies = dependencies.split(',').uniq.join(',')
description = doc.css('#pdesc').text.strip
if doc.css('#content h1').text
version = doc.css('#content h1').text.strip.scan( /\(([^>]*)\)/).last.first
end
File.open("packages/#{package}","w") do |wfptr|
wfptr.puts "PackageId:#{package_id}"
wfptr.puts "Name:#{package}"
wfptr.puts "Deps:#{dependencies}"
end
File.open("packages/#{package}.description",'w') {|wf| wf.write(description.capitalize)}
package_id += 1
puts "Now Processing #{package_id}"
File.open('lastbreak','w') { |fptr| fptr.puts "#{package_id}" }
end
end
Related Topics
Minitest, Test::Unit, and Rails
Bundle Uses Wrong Ruby Version
How to Get a Listing of Only Files Using Dir.Glob
How to Get Today's Date in Ruby 1.9.3
Ruby: "If !Object.Nil" or "If Object"
Can't Setup Ruby Environment - Installing Fii Gem Error
Why Is 032 Different Than 32 in Ruby
Show Markers on Google Maps Dynamically -Rails 3.2
Validate That String Contains Only Allowed Characters in Ruby
Parsing Large Xml with Nokogiri
How to Create an Operator for Deep Copy/Cloning of Objects in Ruby
Does Anyone Have Parsing Rules for the Notepad++ Function List Plugin for Ruby and Rake
How to Simplify or Clean Up This Anagram Method
How to Get a Reference to a Method
How to Test Whether a String Would Match a Glob in Ruby
Should I Be Using Rails or Ruby for This Website Application? How