I am trying to create a pdf using wicked-pdf from Ruby On Rails. It works great in development mode, but when I deploy in production I get the error:
wkhtmltopdf is not executable
I have the wkhtmltopdf executable located at:
rails_root/bin/wkhtmltopdf-i386
Warbler is setup to include the bin folder in the war:
config.includes = FileList["classes/*","bin/*"]
I have wicked pdf configured to find the bin in the correct spot:
WickedPdf.config = {
:exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
}
I run warbler and then deploy the war on jBoss application server. When I try to generate a PDF I get the error about it not being executable. It runs fine in development mode - not in a war.
The permissions on the binary should be fine:
-rwxr-xr-x 1 username group 11446024 Apr 3 11:40 wkhtmltopdf-i386
Instead of manually including the wkhtmltopdf binary, I tried using wkhtmltopdf-binary gem. This too worked fine in development mode, but Wicked PDF can't find the binary in production.
Update: I changed the wicked-pdf config to point to the binary provided by 'wkhtmltopdf-binary' gem when in production mode. It also is getting wkhtmltopdf is not executable error. The path ends up being: jboss-5.1.0.GA/server/default/tmp/3j001-3g0fg5-hf2xi49o-1-hf2xiuld-9q/myrailsapp.war/WEB-INF/gems/gems/wkhtmltopdf-binary-0.9.9.1/bin/wkhtmltopdf_linux_386
Do you install wkhtmltopdf separately or allow your gem file to install it?
I'd do the following:
gem 'wicked_pdf', '~> 0.9.10'
gem 'wkhtmltopdf-binary', '~> 0.9.9'
and then set the config:
WickedPdf.config = {
exe_path: "#{ENV['GEM_HOME']}/gems/wkhtmltopdf-binary-#{Gem.loaded_specs['wkhtmltopdf-binary'].version}/bin/wkhtmltopdf_linux_386"
}
This bit #{Gem.loaded_specs['wkhtmltopdf-binary'].version} queries your gems to find the current version if you were to ever change the version of the gem, your prod server would still be able to find the proper folder.
I faced this same issue when working with a Rails 5.2.3 application on an Ubuntu 18.04.
The error displayed is this:
Gem::Exception: can't find executable wkhtmltopdf for gem wkhtmltopdf-binary. wkhtmltopdf-binary is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
Here's how I solved it:
I simply added the wkhtmltopdf-binary gem to the production group which already had the wkhtmltopdf-heroku in the Gemfile.
group :production do
gem 'wkhtmltopdf-heroku'
gem 'wkhtmltopdf-binary'
end
And then installed the gem
bundle install --without development test
If you're running on a production server, please endeavour to install the libxrender1 library, since it's a dependency for wkhtmltopdf (for rendering PDFs), to avoid en error when rendering PDFs.
sudo apt-get install libxrender1
That's all.
I hope this helps
Related
On my Macbook I have wkhtmltopdf installed and when I do wkhtmltopdf -V I get:
wkhtmltopdf 0.12.2.1 (with patched qt)
When I deploy the Rails app to Heroku, the PDF renders different. So I checked the version on Heroku with heroku run "wkhtmltopdf -V", but that gives me:
bash: wkhtmltopdf: command not found.
The PDF itself renders fine on Heroku, so there must be a wkhtmltopdf installed I guess? I followed these instructions to create a buildpack, but with no change when I request the version:
https://elements.heroku.com/buildpacks/rafaelp/heroku-buildpack-wkhtmltopdf
In the Gemfile I have this:
group :development do
gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1'
end
So, how do I properly install wkhtmltopdf on Heroku and make sure the version is the same as on my Macbook?
You're probably seeing a conflict in versions here between a binary bundled in the gem you're using in development, and another binary.
You should manually manage your wkhtmltopdf binary manually in development & heroku (homebrew/apt-get + buildpack), or use a gem which includes the binaries in both environments. Not a mix of both, as you'll get inconsistent results.
Personally, I use this buildpack on heroku and use brew to install the version I need locally for development.
I was making a chat app with ruby on rails 5.
I tried to implement image sending function in my app.
I followed the instruction of the below blog.(sorry in Japanese)
http://yamakichi.hatenablog.com/entry/2017/01/18/232856
1) bundleinstall below gems
gem "carrierwave"
gem "piet"
gem "mini_magick"
2) Create uploader
But it didn't work.
I removed gem "piet" by bundle upload after I deleted it.
At this moment, I realized that about 8000 unknown files were installed.
Below are examples of the file names installed.
vendor/bundle/ruby/2.3.0/bin/rake
vendor/bundle/ruby/2.3.0/cache/concurrent-ruby-1.0.5.gem
vendor/bundle/ruby/2.3.0/gems/concurrent-ruby-1.0.5/lib/concurrent/hash.rb
....
All the files start with "vendor/bundle/ruby/2.3.0".
If I delete this "vendor/bundle/ruby/2.3.0" file, I can remove every unnecessary files.
But next, I couldn't turn on local server.
It said,
"Could not find rake-12.1.0 in any of the sources"
"Run bundle install to install missing gems."
And if I bundleinstall, this 8000 file were installed again.
How can I avoid this problem?
The gem piet may be a dependency of another gem in your Rails project. When in doubt you can delete your copy of Gemfile.lock and run bundle again. It will auto-generate a new copy with the correct dependencies.
If you're working on a Rails project, it's totally normal for ~8,000 files to be installed since Rails itself relies on quite a few gems.
One way to cut down on the number of files installed by bundler is to skip the documentation within each gem. That can be accomplished by adding this to your local ~/.gemrc file
gem: --no-document
I've an issue with gem file development, for example I'm creating a gem with executable command.
It all works well, I can run command, BUT I've issue that if I'm trying to run command inside another project folder it's USING Gemfile from this second project.
Can I somehow disable it?
I want only to use Gemfile (and .gemspec) from my gem, and not with folder where it was executed.
I have a gem github.com/igorkasyanchuk/rails_db (version in master branch is not released yet, so you need to build it locally), gem build ..., then gem install ..., and then go to your project dir and run "railsdb". When you run it, it's trying to load gems from local folder Gemfile.
Thanks
Igor
If you are using the rubygems-bundler gem, executing commands provided by a gem will load the bundle of your current directory. You can prohibit this from happening for a particular gem providing commands in various ways. One way:
export NOEXEC_EXCLUDE=my_gem_command
See https://github.com/rvm/rubygems-bundler for more information about rubygems-bundler.
C:\sites\srhapp>rails generate controller home index
C:/Ruby21/lib/ruby/gems/2.1.0/gems/execjs-2.5.2/lib/execjs/runtimes.rb:48:in `au
todetect': Could not find a JavaScript runtime. See https://github.com/rails/exe
cjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
This are the error messages i get. kindly help me out .
Install nodejs. That may help here.
Follow this.
Now that you have Nodejs installed, see if any of these can help with the error you are getting (I was going to comment on jon snow's answer, but my suggestions became too long.):
Make sure you have C:\Windows\System32 in your system's PATH variable.
Close and then restart your command console.
Type node -v into the console. Does Nodejs respond?
Change the therubyracer line in your Gemfile to gem 'therubyracer', {:platforms => [:ruby]}. As far as I know, therubyracer isn't for Windows, but declaring it this way lets it still be used in Heroku if you plan on using that later. Run bundle install after you make this change.
Edit
Do you necessarily need Puma in your Windows development environment? If you only need it for deployment on Heroku, the easiest way that I have found to get around its difficulty with Windows is by putting it into the production group along with any other gems Heroku requires.
Gemfile
...
group( :production ) do
# Serves static assets in Heroku deployment.
gem 'rails_12factor'
# Web server for use with Heroku.
gem 'puma'
# Database used by Heroku.
gem 'pg'
end
...
That way, you can simply exclude those gems when you bundle install in your local development environment.
$ bundle install --without production
If you really do need Puma on a Windows environment, you will have to install OpenSSL libraries and headers (so I have heard; I haven't tried it myself). The comment by luislavena on this page should help you in that case.
My computer works on a proxy. So in order to install gems I use the following command
gem install -p http//#{proxy-server}:#{port} rails
If i use the normal gem install command, I get an error could not find gem. I installed rails 3.1 today and tried to create a new project. Half the way while creating the files, the generator started executing run bundle install and ended up giving the same error
Fetching source index for http://rubygems.org/
Could not reach rubygems repository http://rubygems.org/
Could not find gem 'turn (>= 0, runtime)' in any of the gem sources listed in your Gemfile.
The generator is trying to install some gems without proxy. How can I override this existing functionality? I want the generator to use gem install -p http//#{proxy-server}:#{port} #{gem} instead of gem install #{gem}
Add the given option to your gemrc file
gem: -p http//#{proxy-server}:#{port}
Under unix this file is located under ~/.gemrc, for windows I don't know, but according to this answer should be
# Under windows XP
C:\Documents and Settings\All Users\Application Data\gemrc
# Under Windows Vista/Seven
C:\ProgramData\gemrc for windows Vista/Seven
The rc file needs to be created if not present.