如何在生产导轨 4 中提供指纹 css 路径 [英] How to give fingerprint css path in production rails 4

查看:23
本文介绍了如何在生产导轨 4 中提供指纹 css 路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 imgkit 拍摄我的网页快照.我跑:

I am using imgkit to take snapshot of my webpage. I run:

RAILS_ENV=production bundle exec rake assets:precompile 预编译我的资产.

app/assets目录下的所有文件都编译为public/assetsapplication.css 编译为 application-7a23a105125768e41d9d24aee4553615.css.

All file of app/assets directory are compiled to public/assets application.css compiled as 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 not found 错误...

I don't know how to resolve /public/assets/application.css not found error...

没有那个文件或目录 - public/assets/application.css

No such file or directory - public/assets/application.css

我正在使用 https://github.com/csquared/IMGKit/issues/36 获取 css 并在我的快照中工作

I am using https://github.com/csquared/IMGKit/issues/36 to get css and work in my snapshot

编辑

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

推荐答案

可以使用Sprockets::Rails::Helper#asset_digest_path,找到这里.由于您在控制器中,您可以使用

You can use Sprockets::Rails::Helper#asset_digest_path, found here. Since you are in the controller, you have access to it with

self.class.helpers.asset_digest_path('application.css')
# => "application-7a23a105125768e41d9d24aee4553615.css"

同样,asset_path 将生成 application.css 文件的路径

Similarly, asset_path will yield the path to the application.css file

self.class.helpers.asset_path('application.css')
# => "/assets/application-7a23a105125768e41d9d24aee4553615.css"

这篇关于如何在生产导轨 4 中提供指纹 css 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆