2014-05-19 3 views
4

imgkit을 사용하여 웹 페이지의 스냅 샷을 찍습니다. 실행 :프로덕션 레일에서 지문 CSS 경로를 제공하는 방법 4

RAILS_ENV=production bundle exec rake assets:precompile 내 자산을 사전 컴파일하려면.

app/assets 디렉토리의 모든 파일은 application-7a23a105125768e41d9d24aee4553615.css로 컴파일 public/assets application.css로 컴파일됩니다.

내 컨트롤러 코드입니다 : 내가 ... /public/assets/application.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') 

해당 파일이나 디렉토리 - 공공/자산 없습니다/application.css

내 스냅 샷에

편집을 CSS와 작업을 얻을 수 https://github.com/csquared/IMGKit/issues/36을 사용하고 있습니다 당신은 Sprockets::Rails::Helper#asset_digest_path 사용할 수 있습니다

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 
+0

의 경로를 얻을 것인가? 개발에 어떤 영향도 미치지는 않을 것입니다. – matanco

+0

https://github.com/csquared/IMGKit/issues/36에서 언급했듯이 미리 컴파일했습니다! –

+0

누구든지 이걸 극복 할 수 있습니까 –

답변

5

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" 
+0

'해당 파일이나 디렉토리가 없습니다!'라는 메시지가 나타납니다. 불행 –

+0

프로덕션 모드에서는 어떻게됩니까? 'RAILS_ENV = production rake assets : precompile' 그리고 나서'RAILS_ENV = production rails console' 그리고 거기에'ApplicationController.helpers.asset_path ('application.css')'? 애셋을 컴파일 한 후에 public/assets 폴더에'application.css' 파일이 있습니까? – hjing

+0

application-7a23a105125768e41d9d24aee4553615.css 파일이 application.css 대신에 만들어졌습니다. 4 –

관련 문제