Right now I am working on rails 3.0.0. If I run my project in terminal, I get this warning. Please help me.
/usr/share/ruby-rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.0.0/lib/action_dispatch/http/mime_type.rb:98: warning: already initialized constant PDF
You might have this in your config/initializers/mime_types.rb file.
Mime::Type.register 'application/pdf', :pdf
It looks like newer versions of rails already registers it.
Try using lookup_by_extenstion before defining it.
I have this on my config/initializers/mime_types.rb file.
Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf)
Related
I am following the simple tutorial here: https://github.com/JonKernPA/gmaps
I keep getting the error:
couldn't find file 'underscore'
(/app/assets/javascripts/application.js:16)
with the following line highlighted:
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
I tried following the suggestions posted in
Gmaps is not defined in rails 4 + gmaps4rails 2.0.3
and I get the same error with the error with the same line highlighted.
When I try to remove the line
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
from application.html.erb, I get the error "Gmaps not found"
Any help appreciated, thanks.
Github link: https://github.com/chiefkikio/circus/
Found a solution. Had to install gem 'underscore-rails' and then bundle it and restart the rails server.
Not a tutorial project, but I use gem 'underscore-rails' (cf https://rubygems.org/gems/underscore-rails) to satisfy gmaps4rails' dependence.
The minified version of Underscore has this line at the end of the file:
//# sourceMappingURL=underscore-min.map
Chrome's developers tools will try to download underscore-min.map when encountering this line. Users won't see this error, unless they open developer tools.
If you want to get rid of this error, either add underscore-min.map to your project (https://github.com/jashkenas/underscore/blob/master/underscore-min.map) or remove that line from underscore.min.js
I also faced the issue and this is what was the reason for me:
The order of required files in my application.js was wrong. I required
//= require_tree . before gmaps. And since I didn't wait until page load in my controller_name.js file, it was loaded first, trying to use Gmaps before the latter was defined.. I thought it might help, but.. I run into another couple issues with ".. is not defined". After small research here is the solution:
wrap you whole custom js in callback for window.load event. I used it with this line:
google.maps.event.addDomListener(window, "load", callback)
Hope this will help
I see the following error after upgrading to rails 3.2.12 with ruby 1.9.2.
ActiveRecord::Fixture::FormatError: a YAML error occurred parsing /SampelRails/user_properties.yml. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html
The exact error was:
Psych::SyntaxError: couldn't parse YAML at line 1 column 0
I have doubled checked the yml files and they seem to be indented properly.
according to https://github.com/rails/rails/issues/2731 this issue seem to be fixed in rails 3.1.1.
just experienced the same issue but the problem was that i was saving my VCR cassettes in test/fixtures/vcr_cassettes/*.yml.
ActiveRecord::Fixture gets confused by yml files with content other than AR fixture data.
The link posted by nathanvda really worked.
Try adding this at the beginning of config/boot.rb
require 'yaml'
YAML::ENGINE.yamler= 'syck'
Rails 3 - 'Couldn't parse Yaml'
I just had the same issue. Solved it by removing a dummy fixture file from fixtures directory. That file had nothing but comments in it.
Background
After reading around it seemed to me that Prawn is out and wkhtmltopdf is in. It also seems like the PDFKit and wicked_pdf gems for Rails are the new cool. So I found a screencast by Ryan on how to use PDFKit. I installed everything, tested wkhtmltopdf on the CLI with no problems, fiddled around with Rails settingsto run multiple processes so the asset pipeline works, and all seemed good, except I'm still stuck at the very end of the process (actually getting the PDF response from the server).
Question
When I request a .pdf version of my view (I'm using the PDFKit Middleware option) my browser just sits there waiting for a response, but as soon as I kill the Rails process the PDF I expected to get only then pops up in my browser window. What gives?
What I'm Using
OS: OSX 10.8.1
Rails: 3.2.8
Ruby: 1.9.3
wkhtmltopdf: 0.11.0_rc1 (although when I run wkhtmltopdf -V it says 0.10.0_rc2)
qt: 4.8.2
What I've Done
used the PDFKit middleware by loading config.middleware.use "PDFKit::Middleware" in my application.rb file.
included gem 'pdfkit' in my Gemfile and installed it with Bundler
set the .pdf mime-type in my mime_types.rb initializer with Mime::Type.register_alias "application/pdf", :pdf
added config.threadsafe! to config/environments/development.rb for multiple threads so asset pipeline doesn't conflict with PDF engine
tested wkhtmltopdf http://www.google.com google.pdf and it generated a PDF of the Google homepage as expected
tried swapping PDFKit for wicked_pdf and encountered the same problem (hanging, but when Rails process is killed the PDF renders as expected)
What it Looks Like
This is the regular html page rendered by Rails (I've blurred the client details):
This is the CLI output by Rails when I try to navigate to localhost:3000/some/path.pdf. (the app hangs while waiting for a response):
When I finally kill the Rails process with ctrl-c the PDF finally shows up in the browser as I expected to see it (CSS and HTML rendered properly, so assets seem to load fine):
Conclusions So Far
Swapping PDFKit for wicked_pdf and getting the same results seems to make me think the problem isn't with those libraries, but something to do with my development environment. But wkhtmltopdf runs fine off the command line, so that makes me think that it and QT are doing their job. The problem must be in Rails. Maybe I'm not configuring something properly?
Plea for Help
How do I determine what exactly the problem is and how do I fix it?
I'll love you if you can help me <3
Update
I've also tried using an alternative method of rendering the PDF (with .to_pdf) without the middleware option as follows (doing this I commented out config.middleware.use "PDFKit::Middleware" from my application.rb file):
respond_to do |format|
format.html
format.pdf do
html = '<html><body>This is a test.</body></html>'
#pdf = PDFKit.new(html)
send_data #pdf.to_pdf,
:filename => 'whatever.pdf',
:type => 'application/pdf',
:disposition => 'attachment'
end
end
The problem is with wkhtmltopdf itself, specifically, any version after 0.9.9. wkhtmltopdf hangs when run directly from the command-line.
Steps to correct:
brew uninstall wkhtmltopdf
cd /usr/local/Library/Formula/
git checkout 6e2d550 /usr/local/Library/Formula/wkhtmltopdf.rb
brew install wkhtmltopdf
Then verify the correct version is installed wkhtmltopdf --version which should yield wkhtmltopdf 0.9.9
Citations:
https://github.com/mileszs/wicked_pdf/issues/110
http://wearepandr.com/blog/article/homebrew-and-installing-old-package-versions#blog_nav
Try the last version. The easy way install on MacOS:
brew install Caskroom/cask/wkhtmltopdf
The fix by scarver2 worked for me as advertised. But I needed a more recent version of wkhtmltopdf. Since the homebrew version still seems outdated (it still hangs on the command line), and since there isn't a recent precompiled binary available, I used the os x build script to compile one myself:
$ git clone git#github.com:wkhtmltopdf/wkhtmltopdf.git
$ cd wkhtmltopdf
$ ./build_osx.sh # i'm running 10.9.2
$ bin/wkhtmltopdf --version
Name:
wkhtmltopdf 0.12.1-72a9f2066fe9ffd162dec007a4d9b6a5cd63b670
$ curl www.example.com | bin/wkhtmltopdf - test.pdf # render pdf of example.com
$ open test.pdf # to confirm pdf
I'm using pdfkit 0.6.2 with Rails 3.2.17. I put the binary in /vendor and, in a pdfkit initializer, pointed to it with config.wkhtmltopdf. So far, so good.
I got the same issue. It works when I added: 'config.threadsafe!' in application.rb as the answer in the stack. Hope this help.
Mine was also hanging and opening the wkhtmltopdf icon in the dock.
I actually found the problem for me was I only had 1 unicorn worker process running. Once I added more than 1 it worked fine.
I'm running wkhtmltopdf 0.9.9 on OS X with pdfkit 0.6.2
Exact same symptoms but using WickedPdf currently. At this point, I believe the issue lies with wkhtmltopdf as well.
Unfortunately, neither of the recommendations I've been able to find in Stack/Google worked for me. Instead, I needed to combine several suggestions, including some found in this post.
Solution was:
brew uninstall wkhtmltopdf
find and delete any copies of wkhtmltopdf in /usr/bin
comment WickedPdf.config line in config/initializers
add config.threadsafe! to development.rb
remove middleware and allow 'show' action of main controller to handle pdf requests (may not be necessary)
add wkhtmltopdf-binary to gemfile
bundle
restart server
You may also need to add Mime::Type.register_alias "application/pdf", :pdf to config/initializers/mime_types.rb (for me, this causes 'warning: already initialized constant PDF')
My set-up was: Mac OSX Mountain Lion with Rails 3.2.1, Webrick, Postgres and wkhtmltopdf-binary (0.9.9.1).
Try editing config/initializer/pdfkit.rb in the following way:
PDFKit.configure do |config|
config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
config.default_options = {
:encoding=>"UTF-8",
:page_size=>"A4",
:margin_top=>"0.25in",
:margin_right=>"0.1in",
:margin_bottom=>"0.25in",
:margin_left=>"0.1in",
:disable_smart_shrinking=> false
}
end
I have followed the following railscast about adding pdfkit to an application, and I am having some issues with the generation of pdfs. Here are the following things that I have done:
I downloaded wkhtmltopdf via the homebrew package manager
brew install wkhtmltopdf
Then I added the pdfkit gem to my gemfile and ran the bundle install command. I added the following to my config/application.rb file
require 'pdfkit'
...
config.middleware.use PDFKit::Middleware, :print_media_type => true
I then changed my application layout file to include all stylesheet types.
If I run rake middleware, the command works and I can see the pdfkit middleware
When I try to append pdf to the end of my routes the application just hangs and I have to exit via the command line. If I create a link to the page I want to make into a pdf, it changes all of the markup so it looks like a corrupted file. (it looks like you opened a text file into a word processor or vice versa I can provide images if that helps) If I try to make css changes in my stylesheet they do not go into effect when I view them with the link to pdf. I am assuming that this has something to do with the new asset pipeline in rails has anyone else experienced this issue?
So I was right in assuming that my error had something to do with the asset pipeline, after doing some research it looks like you need to create a new initializer and add the following code:
ActionController::Base.asset_host = Proc.new { |source, request|
if request.env["REQUEST_PATH"].include? ".pdf"
"file://#{Rails.root.join('public')}"
else
"#{request.protocol}#{request.host_with_port}"
end
}
I'm using Princely and Rails 3.
When I try to render a pdf like this..
respond_to do |format|
format.pdf do
render :pdf => "filename", :template => "path/template.pdf"
end
end
The downloaded file is a text/html format.
How can I fix this and make it work. I have already added the line bellow to config/initializers/mime_types.rb
Mime::Type.register "application/pdf", :pdf
I had the same problem yesterday and came across this question in my search for a solution.
In my case, I had the Princely gem installed globally (well, in my global RVM repo) rather than anywhere in my project's directory structure. So none of the Princely code was ever being loaded. I ended up making a new "prince.rb" file in my project's conf/initializers with the following:
require 'princely'
require 'princely/rails'
At that point I still got rails errors because Princely 1.2.5/lib/princely/pdf_helper#stylesheet_file_path refers to ActionView::Helpers::AssetTageHelper, which is apparently a Rails 2ism. I just changed that method's body to "return stylesheet" and then everything worked.
I'm still fairly new to Rails; maybe someone that knows more can chime in with a better way.