Add basic set of error pages
This commit is contained in:
parent
823284d6ba
commit
d649dc7da3
10 changed files with 115 additions and 41 deletions
29
lib/tasks/app.rake
Normal file
29
lib/tasks/app.rake
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
desc "Generates error pages"
|
||||
task generate_error_pages: :environment do
|
||||
# unless Rails.env.production?
|
||||
# puts "Skipping generate_error_pages page generation outside production"
|
||||
# next
|
||||
# end
|
||||
|
||||
Rails.application.config.action_controller.perform_caching = false
|
||||
pages = {
|
||||
"error_pages/not_found" => "404.html",
|
||||
"error_pages/unprocessable_content" => "422.html",
|
||||
"error_pages/internal_server_error" => "500.html"
|
||||
}
|
||||
|
||||
pages.each do |page, output|
|
||||
puts "Generating #{output}..."
|
||||
outpath = Rails.root.join("public", output)
|
||||
renderer = ApplicationController.renderer.new(http_host: ENV.fetch("APP_HOST") { "jwa11y.top" }, https: true)
|
||||
html = renderer.render(template: page, layout: "layouts/errors")
|
||||
if html.present?
|
||||
File.delete(outpath) if File.exist?(outpath)
|
||||
File.open(outpath, "w") do |f|
|
||||
f.write(html)
|
||||
end
|
||||
else
|
||||
puts "Error generating #{output}!"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue