3

我的应用程序有一个活动数据库,我正在尝试使用 IMGKit 将活动的显示视图呈现为图像文件,然后可以在其他平台上使用。我觉得我已经正确实现了 IMGKit,但我得到的只是一张空白图像。

控制器动作:

def show
    @activity = Activity.find(params[:id])

    respond_to do |format|
      format.html
      format.jpg do
        html = render_to_string
        kit = IMGKit.new(html)
        img = kit.to_img(:jpg)
        send_data img, type: "image/jpeg", disposition: "inline"
      end
    end
end

不知道还有没有其他适用的?

编辑 - 这是它应该呈现的视图,show.jpg.erb

<body>
    <main style="background-color:blue;color:white;">
        <h1 style="font-size:20px;"><%= @activity.title %></h1>
        <h2>Hello</h2>
    </main>
</body>
4

0 回答 0