Errno::ENOENT No such file or directory Rails 4
Change sass-rails version to 4.0.3 and leave the rest as it is. Remove Gemfile.lock when necessary, and then:
$ bundle update
$ bundle install
Finally, don't forget to restart your rails server!
rails 4: Errno::ENOENT (No such file or directory @ rb_sysopen - /assets/
You're asking for the file from a relative path, which might not always work. Try absolute:
@css_asset_bootstrap = File.open(Rails.root + ActionController::Base.helpers.asset_path('bootstrap.css'), "r").read
Another possibly bigger problem is that Heroku has an ephemeral filesystem, and so any changes you write to it can be obliterated at any time when the dyno is culled.
Errno::ENOENT: No such file or directory @ rb_file_s_mtime after feature tests
The fact that the test passes just means that the test does not depend on that image being found. A broken image link will not generally cause a test to fail and it is in fact often the case that test writers do not even bother to supply mock images because it is (perceived to be) too much work and not relevant to the thing being tested.
See folks, this is why we ask for an example. Now that the OP has posted an example, we can see that his problem is browser caching, and will be solved by replacing
product.images.attach io: File.open(path), filename: 'image.png'
with
product.images.attach io: File.open(path), filename: "image-#{Time.now.strftime("%s%L")}.png"
in the helper that does the attachment. I would not have solved this without having the example.
Explanation
ActiveStorage handles saving and serving files. OP was saving and serving images with it, which is definitely what it was intended for. In order to allow for different services to serve files in different ways, ActiveStorage separates the published URL from the actual image serving URL.
The published URL is almost a permalink: it is an encoded version of the database key for the attachment. ActiveStorage processes a request for the URL by looking up where the file is stored and sending a 302 temporary redirect to the URL that can be used to access the file, called a "service URL". When using AWS S3 to store files, the service URL can be a signed URL that expires quickly but nevertheless connects the browser directly to S3 rather than having to go through the web server as intermediary.
By default, the service URL is good for 5 minutes, and ActiveRecord explicitly sets
Cache-Control: max-age=300, private
on the 302 redirect. The browser caches this redirect response and for the next 5 minutes the browser will not even attempt to use or verify the published URL, it will immediately replace the public URL with the cached service URL.
Unfortunately, while the public URL is predictably recreated, the service URL is randomly generated, so when the browser does its automatic redirection, the previously valid service URL no longer works. The solution (or workaround, depending on your point of view) is to distinguish the public URLs by including a timestamp in the filename, so that tests will not reuse public URLs.
Sidenote
By the way, you should not be using url_for
with image_tag
. Change your ERB from
= image_tag url_for(product.image.variant(resize: "120x120"))
to
= image_tag(product.image.variant(resize: "120x120"))
Rails is smart enough to handle either case, but the latter way is the recommended way.
Errno::ENOENT (No such file or directory - )
You have to
require 'open-uri'
So,
require '/home/user/Test.rb'
require 'open-uri' # sometimes without this line, we get the exact error message in ruby on rails..
(or)
Try to reboot your server, sometimes its fix it..
Getting Errno::ENOENT: No such file or directory @ rb_sysopen When trying to open remote file url in Roo gem(Ruby on rails)
Finally following code is worked for me.
spreadsheet = Roo::Spreadsheet.open(open(imported_file.file_url), extension: File.extname(imported_file.file_url).gsub('.','').to_sym) rescue nil
Related Topics
Delayed_Job: Job Failed to Load: Uninitialized Constant Syck::Syck
Ruby 2.1 with Erubis Template Engine
Loop Within Loop in Rails Controller
P Method in Ruby Hard to Search For
How to Turn Off Bigint Primary Keys in Rails 5.1
Which Global Variable Is for Last Expression
Disabling Irb Autocomplete on Heroku
Recursively Convert Hash Containing Non-Utf Chars to Utf
Count Iteration on the Enumerable Cycle
What Is the Directory Structure for Adding Sorbet Rbis to a Gem
Rails: Chartkick Cummulative User Graph
Twitter::Error::Unauthorized in Postscontroller#Create - Invalid or Expired Token
Ruby Daemon Process to Keep Objects Alive for Transient Ruby Instances
Gmaps4Rails:Setting Map Width and Height
Permanently Switching User in Capistrano 3 (Separate Authorization & Deploy)
Official Expansion of ||= Conditional Assignment Operator