Help us understand the problem. What is going on with this article?

WindowsでRGhost-Railsを使ってPNG画像を作成すると画像が壊れる。

More than 5 years have passed since last update.

バイナリで処理していないため[\x0D]や[\x0D\x0A]が[\x0A]に変換されてしまうからっぽい。

... \gems\rghost_rails-0.3.3\lib\rghost_rails.rbの44行目を修正して対処。

data = output.readlines.join

data = File.binread(output)

RGhost-Rails [https://github.com/shairontoledo/RGhost-Rails]

require 'rghost'

RGhost::Document.class_eval do
  alias_method :grid, :rails_grid
end

class ActionController::Base
  def rghost_render(format, options)
    report = options.delete(:report)

    template = case report
    when Hash
      File.join(report[:controller] || controller_name, report[:action].to_s)
    when String, Symbol
      File.join(controller_path, report.to_s)
    when NilClass
      File.join(controller_path, action_name)
    end
    template_file = begin
      template = view_paths.find_template(template, "rghost.rb", false)
      template.filename
    rescue NoMethodError 
      fname = "#{template}.rghost.rb"
      template_dir = view_paths.detect do |path|
        File.exists? File.join(path.to_s,fname)
      end
      File.join(template_dir.to_s,fname)
    end

    ActionView::Helpers.included_modules.each do |m|
      extend m
    end
    lines = File.readlines(template_file.to_s)

    doc = eval(lines.join)

    filename = options.delete(:filename)
    disposition=options.delete(:disposition) || 'attachment'
    rghost = doc.render(format, options)
    output = rghost.output

    raise "RGhost::Error #{rghost.errors} - #{output}" if rghost.error?

#    data = output.readlines.join
    data = File.binread(output)

    rghost.clear_output

    send_data(data, :filename => filename, :disposition => disposition, :type => Mime::Type.lookup_by_extension(format.to_s))
  end
end

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away