Mime uninitialized constant :: PDF using the Wicked PDF gem / Rails 3 project

I get this error when I try to submit my form (it is assumed that the PDF will be created using the Wicked PDF gem when submitting the form) -

NameError in PostsController#create uninitialized constant Mime::PDF Rails.root: /Users/fkhalid2008/littlechits Application Trace | Framework Trace | Full Trace app/controllers/posts_controller.rb:42:in `create' app/controllers/posts_controller.rb:39:in `create' 

How to fix it? The corresponding code is below.

POSTS CONTROLLER

  def create @post = Post.new(params[:post]) @post.user = current_user respond_to do |format| if verify_recaptcha && @post.save format.html { redirect_to :action=> "index"} format.pdf do render :pdf => "file_name" end else format.html { render :action => "new" } format.json { render :json => @post.errors, :status => :unprocessable_entity } end end end 

CONFIG / initializers / WICKED_PDF.RB

 # config/initializers/wicked_pdf.rb WickedPdf.config = { :exe_path => '/usr/local/bin/wkhtmltopdf' } 

Thanks,

Faisal

+8
ruby-on-rails ruby-on-rails-3 wicked-pdf
source share
1 answer

You need to define the PDF MIME type in config / initializers / mime_types.rb

 Mime::Type.register "application/pdf", :pdf 
+11
source share

All Articles