Ruby: No Such File or Directory @ Rb_Sysopen - Testfile (Errno::Enoent)

Ruby: No such file or directory @ rb_sysopen - testfile (Errno::ENOENT)

File.open(..., 'w') creates a file if it does not exist. Nobody promised it will create a directory tree for it.

Another thing, one should use File#join to build directory path, rather than dumb string concatenation.

path = File.join Rails.root, 'public', 'system', 'users', user.id.to_s, 'style'

FileUtils.mkdir_p(path) unless File.exist?(path)
File.open(File.join(path, 'img.jpg'), 'wb') do |file|
file.puts f.read
end

How to fix Errno::ENOENT: No such file or directory @ rb_sysopen ?

link = "https://www.pokemon.com/us/pokedex/"
doc = Nokogiri::HTML(URI.open(link))

Just add the URI

Errno::ENOENT No such file or directory @ rb_sysopen

You almost there, you need just edit a bit:

def page
Caracal::Document.save(Rails.root.join("public", "example.docx")) do |docx|
# page 1
docx.h1 'Page 1 Header'
docx.hr
docx.p
docx.h2 'Section 1'
docx.p 'Lorem ipsum dolor....'
docx.p
...
end

Recipe Compile Error - Errno::ENOENT - No such file or directory @ rb_sysopen

Check out https://coderanger.net/two-pass/ for the full explanation, but tl;dr Chef runs in two passes and at the time that File.open runs, the remote_file resource has only be queued and not actually done anything yet. You don't give enough context here on what you're doing with the file data to say what the correct fix is, but some are outlined in my blog post.

Rspec: No such file or directory @ rb_sysopen -

You can try to use a little different approach:

describe "gets.rb" do
it "should output 'Hello, name!'" do
allow_any_instance_of(Object).to receive(:gets).and_return("lena")

expect { require_relative "../gets.rb" }.to output("Hello, Lena!\n").to_stdout
end
end

allow_any_instance_of I took from https://makandracards.com/makandra/41096-stubbing-terminal-user-input-in-rspec

Reading user input in console applications is usually done using Kernel#gets.

The page suggests to use Object.any_instance.stub(gets: 'user input') but it's deprecated syntax already and I've updated it.

No such file or directory @ rb_sysopen when converting a file to a string

The message “no implicit conversion of Paperclip::Attachment into String” is telling you that File.read expects a string, but the argument that you passed in (record.file) was a Paperclip::Attachment. What you need is a way to get the path associated with that attachment object.

Looking at the source code for Paperclip::Attachment, I see that its to_s method returns a URL. Passing a URL to File.read gives a file not found error because File.read expects a path. In short, you’re passing file://foo/bar to a method that expects just /foo/bar.

I notice that the path method returns a path on the file system (unless the attachment is stored on S3), so try this:

file = File.read(record.file.path)



Related Topics



Leave a reply



Submit