ruby-on-rails – 使用Wicked PDF gem / Rails 3项目的未初始化的常量Mime :: PDF

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 使用Wicked PDF gem / Rails 3项目的未初始化的常量Mime :: PDF前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我尝试提交表单时,我收到此错误(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'

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

POSTS控制器

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

配置/初始化/ WICKED_PDF.RB

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

谢谢,

费萨尔

解决方法

您需要在config / initializers / mime_types.rb中定义pdf MIME类型
Mime::Type.register "application/pdf",:pdf

猜你在找的Ruby相关文章