"Errno::ENOENT in ListingsController#create" in Rails application - ruby-on-rails

After adding include CarrierWave::MiniMagick to my image_uploader.rb file as well as uncommenting the process: resize to fit => [200,300] line inside of image_uploader.rb, whenever I attempt to create a new Listing in my app I receive the following error message:
"Errno::ENOENT in ListingsController#create" with the explanation of "No such file or directory - identify".
It appears the error is occurring in the directory of 'app/controllers/listings_controller.rb' on line 20 inside the "Create" action.
Description of extracted source on the error page shows this:
self.pid = Process.spawn({'LANG' => self.lang}, command, log_opts)
as the line raising an error.
Prior to these two mentioned changes, the new Listing would be created with no issue whatsoever (apart from the attached image being much too large, hence my newest change). I'm using Cloud9 IDE to develop this application, with Puma as my web server, and Heroku as the (intended) future production-grade app host.

No such file or directory - identify
This is mean that ImageMagick package isn't installed in your OS. So, try to find way to install ImageMagick package to your Heroku node.
Update
This answer says that ImageMagic is installed to Heroku already. So, try to add Ruby wrapper of ImageMagick to your Gemfile:
gem 'mini_magick', '~> 4.1.0'

Related

While converting PDF/DOC/DOX to PNG via Rmagick error : No such file or directory # error/blob.c/OpenBlob/2712 - Ruby on Rails

I am succesfully able to convert PDF/DOC/DOCX to PNG using Rmagick gem in Ruby on Rails in my local system.
The algorithm I am following:
1. Fetch the PDF/DOC/DOCX from a given url.
2. Download that PDF/DOC/DOCX file in local project folder temporarily.
download_path_of_document = "#{Rails.root}/path/to/my/local/download_folder"
open("https://my-url.com") do |doc|
File.open(File.join(download_path_of_document, ".#{extension according to file doc/docx/pdf}"), "wb") do |file|
file.write(doc.read)
end
end
3. Pass that file through the RMagick convertor code by mentioning the path of that locally downloaded file.
4. Get it converted to PNG successfully.
my_converted_pngs = Magick::ImageList.new(File.join(download_path_of_document, ".#{extension according to file doc/docx/pdf}"))
5. Delete the downloaded file that was downloaded in step 2.
This method is working absolutely fine in my local system (environment).
But something weird is happening in my staging server.
I am getting an error like : unable to open image `/tmp/magick-14238gTk5-CaYAECT': No such file or directory # error/blob.c/OpenBlob/2712. The weird thing is that I am getting this error only when I pass DOC and DOCX file in step 3; in case of PDF it is working fine.
Kindy please help. (If any doubt regarding questions please ask multiple times in comments)
ruby - 2.2.2
rails - 4.2.2
gem - rmagick
Hey I don't know if this will help, but I had this similar problem which would return the same error. For my use case I was requesting a page which was doing 2 simultaneous process. First process was fetching an image, second process was generating the image that was to be fetched.
I discovered that because rails Puma server is single threaded, my computer would not be able to execute both of these processes at the same time.
What I did is I added another concurrency to Puma.
#puma.rb
#uncomment this line and add a concurrency of 2
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
Now kill rails server.
Next time you run rails server you should be able to see something different. Process workers shouldve been increased to 2.
If you don't see this change try entering bundle exec puma -C config/puma.rb
Hope this was of help.

'Cannot Load This File' Error for gem built in the project

I am new to API integration and API calls. For the API I am using, I have to build the gem within the project and require it in the controller I will make API calls in.
When requiring the gem, despite making several changes between a relative and absolute path, whenever I run the project locally I keep encountering a 'cannot load such file' error. But the path is correct.
I've tried this:
'../../lib/learning_studio_authentication-0.0.1.gem'
and the full path.
Additionally, my local gems are not showing up when I run 'bundle install' from the command line.
Any help would be greatly appreciated!

MiniMagick error. undefined method 'resize'

This error only happens when executed by the Ruby on Rails server.
I've tried bypassing Carrierwave's resize option by implementing my own but it has the same result.
when I run a script from command line (in which I require the 'mini_magick' gem). It all works flawlessly.
the MiniMagick gem seems to be installed correctly and to be honest I'm kinda out of ideas to tackle this problem.
some versions (not sure if usefull or not):
ruby - 1.9.3p545
rails - 4.1.1
mini_magick - 4.0.1
ImageMagick - 6.9.0-0 Q16
Any help is appreciated.
-edit, I'm using windows 8.1
example code:
require 'mini_magick'
filename = 'test.jpg'
image = MiniMagick::Image.open(filename)
image.resize "1000x1000"
image.format "png"
image.write "test.png"
The code above works flawlessly when executed from cmd.
thumb = MiniMagick::Image.open(i.image.path)
thumb.resize "200*200"
code snippet above throws error in RoR when placed in a controller (Create)
alternatively, uncommenting the resize option directly from carrierwave throws the exact same error.
# version :thumb do
# process :resize_to_fill => [200, 200]
# end
Also a little note:
I've disabled minimagicks validations to figure out what causes the error it threw at that time:
Failed to manipulate with MiniMagick, maybe it is not an image? original error: executable not found: "identify"
I hope this clears a few things up.
-edit
I've decided to leave windows as a dev platform and switch to linux as a dev platform. fixed all of my issues (In hindsight my error was probably due to some lacking dependencies on the imagemagick side).
I experienced a similar problem recently with the following environment:
Windows 8.1
Ruby 2.1.5p273
Ruby Dev Kit 2.1.5
Rails 4.2.0.beta4
carrierwave 0.10.0
mini_magick 4.0.1
ImageMagick6.9.0-Q16 installed at C:\ImageMagick-6.9.0-Q16
In the rails console within RubyMine, I would get:
executable not found: "identify"
after keying in just two things:
filename = 'test.jpg'
image = MiniMagick::Image.open(filename)
One of the steps was to add C:\ImageMagick-6.9.0-Q16 to my Windows PATH environment variable. At first, that didn't help. However, after closing and re-opening RubyMine, the problem went away -- I assume because the change to the PATH env var (done with an independent Windows command prompt) didn't affect the RubyMine IDE environment.
executable not found: "identify"
This is an error message from MiniMagick (Source code). I guess, as the error message says, your server cannot find executable "identify".
Make sure that your ENV['PATH'] has the path to where the "identify" exists.
I'm running into the same problem.
it works flawlessly on my localhost, but on the server (windows 2012), it only works as a rake task. when run inside the application, then it fails saying
NoMethodError (undefined method `resize' for #<MiniMagick::Image:0x28c3260>):
Unfortunately, the path variable is set...
I got it to work by doing the minimagick-stuff inside the model instead of the controller.... nasty workaround.

Spree Commerce is working, but no assets.

I'm trying to customize and modify Spree Commerce, but none of the standard asset files/images/views are available under either app/views, lib/assets, or anywhere else I can think to look. I'm trying to go through their tutorials, but I can't find anything to edit. Is there another command I need to decompress everything or something? Thank you so much for any help!
The way I over came this is to download the main spree gem, via github.com, look where the images are located then creating the images I wanted to override in my local app/assets directory with the same path run:
rake assets:precompile:nondigest
restart webrick/pow or any other web server you are running and voila!
I'm guessing you're not really familiar with how gems work. As people here have said, these are not going to automatically show up in your core app directory, but the gemfile and running bundle install knows how to reference them.
So you need to find those gems to figure out the file names, as you said. If you want to view the gemfiles run this command in the terminal:
$ bundle open spree_frontend
If you get this error:
To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR
then you haven't set up the editor, so do this:
export BUNDLER_EDITOR=sublime
Then redo the bundle open command. This should open the spree_frontend directory which will let you investigate the file names/paths and the assets. If you want to change an entire template, you need to create that file matching its name and path exactly as it is in the spree gem (spree/layouts/spree_application.html.erb for example) then when you edit it your rails app will render the code in your core app directory thus overriding the spree gem.
That make sense?

Install barista/coffeescript on Rails 2.3

I am trying to get barista up and running in a Rails 2.3 application (that may not be moved to a new version of rails for the time beeing..). I switched the app to bundle so I added the following gems to my Gemspec:
gem "barista"
gem "json"
Then executed bundle install which run through. Now as far as I understand to "compile" the coffeescript there is a rake task that comes with barista. But it doesn't seem to be installed properly so I can use it with rake. I.e. when I execute rake -T there is no barista:brew
I saw a pending pull request on git hub suggesting to add require 'barista/tasks' but that only resulted in rake not finding it. So what am I doing wrong or more general how do I get up and running with barista on Rails 2.3.x?
It has been some time ago since I used Barista and I have it not in use in any project, so I cannot verify it.
But I remember that one advantage of Barista is, that it waits serving a request until a modified CoffeeScript file is recompiled. This ensures that the browser doesn't request an outdated file.
So there is no need to compile the CoffeeScript files with a Rake task.
CoffeeScript itself comes also with a watch function, that compiles CoffeeScripts when a change is detected:
coffee -w /path/to/scripts
The reason why I stopped using Barista is simply that I discovered Guard. So I wrote guard-coffeescript to compile my CoffeeScripts in the same moment I save the file.
Guard-coffeescript has some advantages over Barista and CoffeeScript:
Fast and low CPU consumption because it relies on file system modification events.
Can be configured in many ways, e.g. multiple source folders and output folders.
Immediate feedback when an error occurs, even with system notifications like Growl.
Note that Rails 2 support for Barista is, according to Barista's README, "untested" (it was originally built for Rails 3 only), so there may be compatibility issues. Also note that you need either therubyracer gem, or the node binary on your system's PATH (or any of the other JS runtimes supported by ExecJS).
Try this:
Add a file named foo.coffee to the folder app/coffeescripts with the contents
alert 'Hello, Barista!'
Now add <%= javascript_include_tag "foo" %> to an ERB file and load that page.
You should get the alert, just as you would if the compiled foo.js were in public/javascripts.
I've successfully integrated barista and rails 2.3.14. In development, when I ask for a js file, the coffeescript file is found and compiled on the fly.
I also successfully ran the barista:brew rake task and the js files were generated.
I did notice that for production, unless I include an ExecJS compatible compiler, I need to precompile my js files before a push, which might be another +1 for the guard solution by #netzpirat.
For reference - I'm using Barista 1.3.0 and coffee-script 2.2. Not sure how that affects things, but thought it was noteworthy.
Also, I added a line to load the barista tasks in my Rakefile:
# in my Rakefile
load "barista/tasks/barista.rake"

Resources