You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

引入Rails_admin后,Ruby on Rails+Wicked_pdf应用启动访问即崩溃求助

Troubleshooting Rails App Crash with wicked_pdf + rails_admin

Hey there, fellow Rails newbie! I’ve been in your shoes—debugging silent crashes is the worst, but let’s break this down step by step to get your app running again.

1. First, Force Visible Error Details

Since your app crashes without any messages, we need to make Rails spill the beans on what’s going wrong. Try starting your server with verbose tracing:

rails s --trace

Or crank up logging verbosity in config/environments/development.rb:

config.log_level = :debug

This should spit out a stack trace or error right before the crash—critical info for pinpointing the issue.

2. Lock in Compatible Gem Versions

wicked_pdf and rails_admin can clash over dependencies, especially with wkhtmltopdf-binary. Let’s set stable, tested versions in your Gemfile:

gem 'wicked_pdf', '~> 2.1.0'
gem 'wkhtmltopdf-binary', '~> 0.12.6.5'

Run bundle update wicked_pdf wkhtmltopdf-binary to install these versions, then restart your server.

3. Isolate rails_admin Configuration

Custom rails_admin initializers might conflict with wicked_pdf’s rendering hooks. Temporarily comment out all custom code in config/initializers/rails_admin.rb (leave only the basic RailsAdmin.config do |config| ... end block) and try starting the server again. If it works, gradually re-add your config lines one by one to find the conflicting setting.

4. Exclude rails_admin from wicked_pdf Processing

Wicked_pdf modifies Rails’ rendering pipeline, which can interfere with rails_admin’s views. Add an exclusion for the admin route in your wicked_pdf initializer (config/initializers/wicked_pdf.rb):

WickedPdf.config do |config|
  # Keep your existing config, then add:
  config.exclude_routes = %r{/admin} # Matches any path starting with /admin
end

Alternatively, skip wicked_pdf’s before actions in the rails_admin controller:

RailsAdmin.config do |config|
  config.actions do
    # Your existing actions...
    controller do
      skip_before_action :set_wicked_pdf_header if respond_to?(:set_wicked_pdf_header)
    end
  end
end

5. Test Components Separately

Let’s narrow down which gem is causing the conflict:

  • Temporarily comment out wicked_pdf from your Gemfile, run bundle install, and start the server. If rails_admin loads fine, the issue is definitely a conflict between the two gems.
  • Re-add wicked_pdf, but remove any custom wicked_pdf code (like controller actions or view helpers) and test again. If it works, your custom code is the culprit.

6. Verify wkhtmltopdf Path

Sometimes wicked_pdf can’t find the wkhtmltopdf binary when rails_admin triggers a different code path. Specify the full path to wkhtmltopdf in your config:

WickedPdf.config do |config|
  # For macOS/Linux:
  config.exe_path = '/usr/local/bin/wkhtmltopdf'
  # For Windows:
  # config.exe_path = 'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe'
end

Start with step 1 first—getting that error message will make everything else easier. Let me know what you find!

内容的提问来源于stack exchange,提问作者Victor Athoti.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 13:27:48