Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
643 views
in Technique[技术] by (71.8m points)

heroku - How to give fingerprint css path in production rails 4

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...