html预编译语句,资产管道中的预编译HTML页面

我最终走上了哈克路线,这不像我想象的那样哈克。

基本上,我创建了一个控制器,路线,并针对这些错误的模板我打算处理:

# config/routes.rb

resources :errors, only: :show

# app/controllers/errors_controller.rb

class ErrorsController < ApplicationController

layout 'errors'

# you may need to disable various filters

skip_before_filter :authenticate_user!

# cache full versions of the pages we generate

caches_page :show

def show

render action: params[:id]

end

end

# app/views/errors/404.html.erb and so on

404 Not Found

然后,我创建了一个Rake任务“拜访”在这些页面中,这将导致控制器缓存的页面中/public/errors:

task :create_error_pages => :environment do

session = ActionDispatch::Integration::Session.new(Rails.application)

%w{401 404 422 ...}.each do |error|

session.get("/errors/#{error}")

end

end 部署期间

现在,我运行此:

RAILS_ENV=production bundle exec rake assets:precompile create_error_pages

来生成我们的静态HTTP错误页面。

这将工作在任何环境config.action_controller.perform_caching = true。这是默认情况下在生产中,但不是在开发中,所以要注意。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值