Uninitialized constant Mime::PDF using Wicked PDF gem / Rails 3 project
Asked Answered
D

1

9

I'm getting this error when I try to submit my form (PDF is supposed to be generated using Wicked PDF gem, on form submission) -

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 do I fix this??? Relevant 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

Deft answered 5/5, 2012 at 10:0 Comment(0)
B
13

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

Mime::Type.register "application/pdf", :pdf
Bandwagon answered 12/7, 2012 at 22:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.