【问题标题】:Prawn in a Ruby on Rails app, failing on productionRuby on Rails 应用程序中的虾,生产失败
【发布时间】:2014-03-05 08:30:12
【问题描述】:

我遇到了在生产中运行 prawn 的问题。

我非常关注 Railscast(修订版 http://railscasts.com/episodes/153-pdfs-with-prawn-revised?view=asciicast)。它在我的开发环境(Mac OS X 10.9.1)中运行良好,但会导致独角兽在我的服务器上动摇。我的生产服务器是(Redhat => Red Hat Enterprise Linux Server release 6.4 (Santiago))。我通过 Gemfile 安装了 gem。

宝石文件:

    gem 'prawn'
    gem 'prawn-qrcode'

控制器:(显示动作)

    def show
      #@classroom = Classroom.find(params[:id])
      @classroom = find_classroom

      @page_title = @classroom.location.name
      @classroom_alt = @classroom.location.name + " - " + @classroom.room_number
      @building = find_building(@classroom.location_id)
      @owner = Owner.find(@classroom.owner_id)
      @room_schedule_contact = RoomScheduleContact.find_by rmrecnbr:(@classroom.rmrecnbr)
      @building_image = @building.picture.url(:medium).to_s
      @building_sign_image = @building.building_sign.url(:thumb).to_s
      @search = Classroom.search(params[:search])

      #@classroom_herprod = Building.find(params[:location_id]).building_short_code
      respond_to do |format|
        format.html # show.html.erb
        format.png  { render :qrcode => "http://rooms.lsa.umich.edu/classrooms/#{@classroom.facility_code_heprod}", :level => :l, :unit => 8 }
        format.pdf do
         pdf = ClassroomPdf.new(@classroom)

          send_data pdf.render, type: "application/pdf",
                                disposition: "inline"
        end
      end
    end

我有一个 pdfs 目录,其中包含一个classic_pdf.rb 文件,其中包括以下内容。

    class ClassroomPdf < Prawn::Document
      def initialize(classroom)
        super(top_margin: 70)

        text "This is a pdf"
      end
    end

(这是从我所拥有的中剥离出来的,但它是在我的开发系统上工作但在生产中失败的最基本版本。

我正在执行以下操作

ruby 2.1.0p0(2013-12-25 修订版 44422)[x86_64-linux] 宝石'rails','4.0.2'

unicorn.stderr.log中的错误如下。

       E, [2014-02-07T12:39:20.400750 #7300] ERROR -- : reaped #<Process::Status: pid 7306 exit 1> worker=1
    I, [2014-02-07T12:39:20.401257 #7300]  INFO -- : worker=1 spawning...
    I, [2014-02-07T12:39:20.463964 #7529]  INFO -- : worker=1 spawned pid=7529
    I, [2014-02-07T12:39:20.521524 #7529]  INFO -- : Refreshing Gem list
    E, [2014-02-07T12:39:29.938423 #7326] ERROR -- : uninitialized constant Prawn (NameError)
        /var/www/rooms.lsa.umich.edu/html/iris/releases/20140207173433/app/pdfs/classroom_pdf.rb:1:in `<top (required)>'
    /var/www/rooms.lsa.umich.edu/html/iris/shared/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'

这是gemfile

    source 'https://rubygems.org'
    ##gem 'rails', '3.2.14'
    gem 'rails', '4.0.2'
    gem 'sqlite3'
    gem 'sass-rails', '~> 4.0.0'
    gem 'uglifier', '>= 1.3.0'
    gem 'coffee-rails', '~> 4.0.0'
    #gem 'jquery-rails'

    gem 'turbolinks'
    gem 'jbuilder', '~> 1.2'
    group :doc do
      # bundle exec rake doc:rails generates the API under doc/api.
      gem 'sdoc', require: false
    end

    gem "haml"
    #gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails'
    gem 'bootstrap-sass', '~> 3.1.0'

    #gem 'google-analytics-rails'

    gem 'font-awesome-rails'

    gem 'protected_attributes'
    gem 'modernizr-rails'
    gem "jquery-rails"
    gem "devise", "3.0.3"
    gem "cancan", ">= 1.6.9"
    gem "rolify", ">= 3.2.0"
    gem 'newrelic_rpm'

    # QR-Code generation
    gem 'rqrcode-rails3'
    gem 'mini_magick'

    gem 'prawn'
    #gem 'prawn', '1.0.0.rc2'
    gem 'prawn-qrcode'
    #gem 'prawnto'

    gem 'capistrano', '2.15.5'
    #gem 'capistrano'
    gem "simple_form"
    gem 'will_paginate', '~> 3.0.5'
    gem "therubyracer", :group => :assets, :platform => :ruby
    gem 'will_paginate-bootstrap'
    #gem 'kaminari'

    ## Used for uploading and resizing images (Need both paperclip and mini_magick)

    gem "paperclip", "3.5.1"

    #gem "meta_search"
    gem "ransack"
    gem 'annotate', ">=2.6.0"

    group :production do
      gem 'unicorn'
    end

有什么想法吗?

【问题讨论】:

  • 请显示你的gemfile?
  • 您确定 gem 在 prod 服务器上安装正确吗?
  • 当我导航到项目(当前版本)目录并检查 Gemfile.lock 虾在那里。我还能做其他检查吗?

标签: ruby-on-rails-4 prawn ruby-2.1


【解决方案1】:

事实证明,我需要手动重启 unicorn 才能正确加载新的 gem 文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多