微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 如何在生产轨道中提供指纹css路径4

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

RAILS_ENV =生产包exec rake资产:预编译预编译我的资产.

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',: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",: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,找到 here.由于您在控制器中,因此您可以访问它

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐