如何在生产轨道中提供指纹css路径4 [英] How to give fingerprint css path in production rails 4
问题描述
我使用 imgkit
来拍摄我的网页快照。我运行:
$ b
RAILS_ENV =生产捆绑包exec rake assets:预编译
预编译我的资产。
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
我正在使用< a href =https://github.com/csquared/IMGKit/issues/36 =nofollow> 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: '传单已成功更新。'}
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
,找到< href =https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/rails/helper.rb#L108 =nofollow>这里。由于您在控制器中,因此您可以使用 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
I am using imgkit
to take snapshot of my webpage. I run:
RAILS_ENV=production bundle exec rake assets:precompile
To precompile my assets.
All file of app/assets
directory are compiled to public/assets
application.css
compiled as application-7a23a105125768e41d9d24aee4553615.css
.
My controller code is:
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')
I don't know how to resolve /public/assets/application.css
not found error...
No such file or directory - public/assets/application.css
I am using https://github.com/csquared/IMGKit/issues/36 to get css and work in my snapshot
edits
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
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"
Similarly, asset_path
will yield the path to the application.css file
self.class.helpers.asset_path('application.css')
# => "/assets/application-7a23a105125768e41d9d24aee4553615.css"
这篇关于如何在生产轨道中提供指纹css路径4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!