Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 594
hikmatyar Avatar asked May 05 '12 10:05

hikmatyar


1 Answers

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

Mime::Type.register "application/pdf", :pdf
like image 181
SupaIrish Avatar answered Nov 15 '22 19:11

SupaIrish