【发布时间】:2014-07-07 08:27:24
【问题描述】:
我正在使用imgkit 拍摄我的网页快照。我跑:
RAILS_ENV=production bundle exec rake assets:precompile 预编译我的资产。
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 not found 错误...
没有这样的文件或目录 - 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', :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
【问题讨论】:
-
为什么要在开发环境中预编译?它不会对开发产生任何影响,你应该只在生产中这样做。
-
如提到的github.com/csquared/IMGKit/issues/36我预编译了它!!
-
谁能帮我克服这个问题
-
application-7a23a105125768e41d9d24aee4553615.css与application.css不同。因此找不到。 -
@scones 我知道但我如何在生产中提供指纹路径
标签: ruby-on-rails heroku ruby-on-rails-4 precompile imgkit