9

当我尝试提交表单时出现此错误(PDF 应该是使用 Wicked PDF gem 生成的,在提交表单时)-

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'

我该如何解决???相关代码如下。

帖子控制器

 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'
}

谢谢,

费萨尔

4

1 回答 1

13

您需要在 config/initializers/mime_types.rb 中定义 pdf MIME 类型

Mime::Type.register "application/pdf", :pdf
于 2012-07-12T22:25:39.513 回答