当我尝试提交表单时,我收到此错误(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