我正在使用 imgkit
来快照我的网页。我运行:
RAILS_ENV=production bundle exec rake assets:precompile
来预编译我的资产。
所有在 app/assets
目录的文件都被编译到 public/assets
中,application.css
被编译为 application-7a23a105125768e41d9d24aee4553615.css
。
我的控制器代码如下:
kit = IMGKit.new(render_to_string(:partial => 'form', :height => 200, :transparent => true, :quality => 10, :layout => false,:locals => {:project => @project}))
# t = kit.to_img(:png)
kit.stylesheets << "#{Rails.root.to_s}/public/assets/application.css"
#file = kit.to_file(Rails.root + "public/pngs/" + "screenshot.png")
file = kit.to_file(Rails.root + "public/assets/" + "screenshot.png")
#send_file("#{Rails.root.to_s}/public/pngs/screenshot.png", :filename => "screenshot.png", :type => "image/png",:disposition => 'attachment',:streaming=> 'true')
我不知道如何解决 /public/assets/application.css
未找到错误...
没有此文件或目录 - public/assets/application.css
我正在使用 https://github.com/csquared/IMGKit/issues/36 来获取CSS并在我的快照中工作。
编辑:
def update
#@kit = IMGKit.new(render_to_string, width: 480, height: 800, :quality => 100)
respond_to do |format|
if @project.update(project_params)
kit = IMGKit.new(render_to_string(:partial => 'form', :height => 200, :transparent => true, :quality => 10, :layout => false,:locals => {:project => @project}))
# t = kit.to_img(:png)
kit.stylesheets << "self.class.helpers.asset_path('application.css')"
#file = kit.to_file(Rails.root + "public/pngs/" + "screenshot.png")
file = kit.to_file(Rails.root + "public/assets/" + "screenshot.png")
#send_file("#{Rails.root.to_s}/public/pngs/screenshot.png", :filename => "screenshot.png", :type => "image/png",:disposition => 'attachment',:streaming=> 'true')
format.html { redirect_to root_path, notice: 'Flyer was successfully updated.' }
format.json { render :show, status: :ok, locatioFlyern: @project }
else
format.html { render :edit }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end