I'm using wicked_pdf in a Rails 4.1 app.
PDF generation works perfectly within my local dev setup. But I get errors when deployed to Heroku.
Checking the logs I see
ActionView::Template::Error (No such file or directory - /app/public/photos/application.js):
associated with the wicked_pdf helpers
<%= wicked_pdf_javascript_include_tag "application" %>
I understood that the wicked_pdf helpers generated absolute urls, so
why am I seeing a relate url originating from the app folder?
How is this path being generated? I have no public/photos folder in
my app!
How do I go about debugging this problem? I'm unsure if this is a Heroku issue, a wkhtmltopdf issue, an asset compilation issue, or...?
Is anyone using wicked_pdf successfully on Heroku?
This is a new issue in Rails 4 (4.1?), where the compiled assets come out with digests like this:
application-4dd5b109ee3439da54f5bdfd78a80473.js
but no plain
application.js
is generated anymore.
You can try this gem https://github.com/alexspeller/non-stupid-digest-assets
or I would recommend base64 encoding your assets like described in this issue:
https://github.com/mileszs/wicked_pdf/issues/257
I'm working on rolling this into WickedPdf very soon, as this is a common issue to have differences in environments due to asset pipeline stuff.
I see that there is no an asets digest in log info that rails use for assets in producation environment.
I think the gem should resolve the issue because it was written for using wikedpdf on Heroku.
You can add it like that:
group :production do
gem "wkhtmltopdf-heroku"
end
Related
I am successfully loading CSS files in my PDF file using wicked_pdf gem helpers:
<%= wicked_pdf_stylesheet_link_tag "pdf" %>
This works great in development, however when i deploy in production the pdf CSS file is not correctly imported. Also note that the file is "pdf.scss.erb" and not just "pdf.css".
I am not sure how to fix this problem. Looking at the server logs, i do not see any missed file warnings.
I myself solved the problem by duplicating the styles right onto the layout page.
However at this github thread people are advising to do several things:
Include the files in your precompile list in config/initializers/assets.rb as described in the Asset pipeline usage section of the README.
Using stylesheet_link_tag wicked_pdf_asset_base64('pdf')
wkthmltopdf not bundling with dependency library to wkthmltopdf can install the gem after installed gem run bundle install
gem "wkhtmltopdf-binary"
Im writing an isolated Rails Engine which has it's own javascript in app/assets which in turn loads a bunch of dependencies that are kept in the engine's vendor/assets.
I've been using the dummy app in the test folder for development and everything has worked as I expect.
If I package the engine up as a gem and install it into a separate rails app, when I try to access the engine in a browser I get the Sprockets::FileNotFound exception couldn't find file.
If I fire up the console and have a look at Rails.application.config.assets.paths it includes mygem/app/assets but not mygem/vendor/assets.
This is where it gets weird. If I change the rails app's Gemfile and load the engine directly from a path, I don't have these problems. I can view my engine in browser without any Sprockets issues. Loading up the console and looking at Rails.application.config.assets.paths shows both path/to/mygem/app/assets AND path/to/mygem/vendor/assets.
I don't get this. Why would I get different behaviour if the engine is being loaded as a packaged gem or directly from a path?
Answering my own question. School-boy error, nothing to do with the asset pipeline, everything to do with adding the vendor path to the gemspec configuration.
s.files = Dir['{app,config,db,lib,vendor}/**/*', 'README.md', 'LICENSE.md']
I installed twitter bootstrap by copying the files into my assets directory as per the instructions here: http://www.erikminkel.com/2013/09/01/twitter-bootstrap-3-in-a-rails-4-application/
After following the instructions exactly as presented and executing "rake assets:precompile RAILS_ENV=development", I am able to use bootstrap 3 in my development rails server.
However, when I try to execute "heroku run rake assets:precompile RAILS_ENV=production", I get this error:
Sass::SyntaxError: Invalid CSS after "...ss","sources":[": expected "|",
was ""less/theme.les..." (in /app/app/assets/stylesheets/application.css) (sass):444
I am not sure what this means. When I open "application.css" in the assets/stylesheets folder, I can't even find a line 444. I do have some scaffold files left over after running "rails g scaffold ..." commands -- could that be causing this problem? And obviously, the deployed heroku app looks like a non-bootstrap app when I view it from the heroku page and throws a "resource not found" error.
In public/assets/application-mydigest.ccs, I found the following line of code that causes the error:
{"version":3,"file":"bootstrap-theme.css","sources":["less/theme.less","less/mixins/vendor-prefixes.less","bootstrap-theme.css","less/mixins/gradients.less","less/mixins/reset-filter.less"],"names":[],"mappings":"AAeA;;;;;;EAME,0CAAA;EC+CA,6FAAA;EACQ,qFAAA;EC5DT;AFiBC;;;;;;;;;;;;EC0CA,0DAAA;EACQ,kDAAA;EC7CT;AFqCC;;EAEE,wBAAA;EEnCH;AFwCD;EG/CI,0EAAA;EACA,qEAAA
However, it seems odd that this would only happen on production. Moreover, the CSS syntax looks fine.
This error means the assets compilation failed because of an invalid css syntax into a file you require in application.css.
In bootstrap repository there is a less directory and you can't precompile less files with rails.
If you want to use Rails and Bootstrap on a production environment I think use bootstrap-sass gem is a better option
Have you tried using rails-assets instead of the referenced method of adding Bootstrap 3? I use it on Heroku with success... and just add my own custom Bootstrap css in my normal assets folders which get loaded after the vanilla Bootstrap 3 and override it. Just add gem 'rails-assets-bootstrap' along with source 'https://rails-assets.org' to your gem file. May help diagnose if nothing else.
EIther of the two things you must take care to avoid assets compilation errors when you go live.
- Add all your assets(js/css) in manifest file(application.js/application.css)
- OR
- use assets.precompile=%w(custom.css custom.js) directive to handle them explicitly
because when u precompile...rails copies everyting(images/fonts) except js/css into public folder to be taken care by the server(apache),hence the setting # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false in production.rb during assets precompile fallback is disabled by default in production/staging as Rails assumes it will be handled by webserver.Hence we have manifest file to define our assets which gets precompiled during assets:precompile and verified by looking for public/assets/javascripts/application.css/js after compilation which gets created requiring all files mentioned in app/assets/stylesheets/application.css and app/assets/javascripts/application.js after running assets:precompile...so hope u know where you missed.
FOR MORE DETAILS..REFER this
rails beginner here
I am trying to set an app to production but having big issues with the asset pipeline. Under development every asset is generated under /assets/blabla.extension
However, I am running nginx and when running rake assets:precompile it creates assets under /public/assets as it should. But when I visit my app it generates urls like /application.css and not /assets/application-digestq12343.css as it should.
I think there is an easy fix to this problem.. but I cannot find it. Please help me!
Update:
From the documentation I read that Sprockets "default" is /assets but it certainly isn't in my application. I use the latest version of rails. Can the documentation be outdated?
http://edgeguides.rubyonrails.org/asset_pipeline.html
Even if I add config.assets.prefix = "/assets" to my production it would still mean that I would not load the assets since the digest would be missing.
I believe this is the same problem I was experiencing. Instead of using url()in your css (or scss), use asset-data-url() and add config.assets.enabled = true to your application config file. Then, rake assets:precompile before you push.
I am new to rails and using version 3.1.0 and trying to deploy to heroku. I have a very simple application that i have managed to get up and running on heroku after working my way through several issues. I used the command
bundle exec rake assets:precompile
to get heroku to load the assets for the application (i read that heroku requires this for version 3.1.0). The problem is that when i try to run the application, the server gives the error
ActionController::RoutingError (No route matches [GET] "/assets/all.js"):
i have all of the required javascript files in public/javscripts but i cannot find any version of all.js in the assets directory. I have included
config.assets.precompile << '*.js'
in config/application.rb but to no avail.
I was wondering if someone could tell me how I get the precompile to create all.js in the assets directory or if I am completely off track here. i was under the impression that the precompile function compiled all of the javascript files into a single optimized file.
Also, if anyone has any good links for a beginner to understand how the precompile functionality works in rails I would be very appreciative.
Thanks in advance.
The best guide is the official rails guide. There is also the Railscast about it.
In a nutshell your Javascript files go in app/assets/javascript from where the precompile task will process them and put then in the public/assets directory. You should not have to change the precompile config option if the follow the defaults. Don't forget to the use the correct helpers to reference your files.
Read the resources above, and if you are converting an existing app watch the Railscast and follow the last section of the guide - these should point you in the right direction.