Fix rendering of error pages to remove deprecation warning for rails 6.0
This commit is contained in:
parent
b5a46cf7bb
commit
17b84d3ddd
5 changed files with 9 additions and 49 deletions
|
|
@ -1,10 +1,5 @@
|
||||||
- content_for(:page_title) do
|
- content_for(:page_title) do
|
||||||
The page you were looking for doesn't exist (404)
|
The page you were looking for doesn't exist (404)
|
||||||
|
|
||||||
.transparent.big-number
|
|
||||||
404
|
|
||||||
%h3
|
%h3
|
||||||
These are not the kittens you're looking for. Move along.
|
These are not the kittens you're looking for. Move along.
|
||||||
%p
|
|
||||||
%a{href: "javascript:history.back()"}
|
|
||||||
Go Back?
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
- content_for(:page_title) do
|
- content_for(:page_title) do
|
||||||
The change you wanted was rejected (422)
|
The change you wanted was rejected (422)
|
||||||
|
|
||||||
.transparent.big-number
|
|
||||||
422
|
|
||||||
%h3
|
%h3
|
||||||
The change you wanted was rejected.
|
The change you wanted was rejected.
|
||||||
%p
|
%p
|
||||||
Maybe you tried to change something you didn't have access to.
|
Maybe you tried to change something you didn't have access to.
|
||||||
|
|
||||||
%p
|
|
||||||
%a{href: "javascript:history.back()"}
|
|
||||||
Go Back?
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
- content_for(:page_title) do
|
- content_for(:page_title) do
|
||||||
We're sorry, but something went wrong (500)
|
We're sorry, but something went wrong (500)
|
||||||
|
|
||||||
.transparent.big-number
|
|
||||||
500
|
|
||||||
%h3
|
%h3
|
||||||
Internal server error.
|
Internal server error.
|
||||||
Our bad! Sorry about that. :(
|
Our bad! Sorry about that. :(
|
||||||
|
|
@ -10,7 +8,3 @@
|
||||||
- if AppConfig.admins.podmin_email?
|
- if AppConfig.admins.podmin_email?
|
||||||
%p
|
%p
|
||||||
Drop us an email to <a href="mailto:#{AppConfig.admins.podmin_email}">#{AppConfig.admins.podmin_email}</a>.
|
Drop us an email to <a href="mailto:#{AppConfig.admins.podmin_email}">#{AppConfig.admins.podmin_email}</a>.
|
||||||
|
|
||||||
%p
|
|
||||||
%a{href: "javascript:history.back()"}
|
|
||||||
Go Back?
|
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,12 @@
|
||||||
|
|
||||||
= yield(:head)
|
= yield(:head)
|
||||||
|
|
||||||
%body{class: "error-#{@code}", id: "error_#{@code}"}
|
%body{class: "error-#{local_assigns[:code]}", id: "error_#{local_assigns[:code]}"}
|
||||||
|
.transparent.big-number
|
||||||
|
= local_assigns[:code]
|
||||||
|
|
||||||
= yield
|
= yield
|
||||||
|
|
||||||
|
%p
|
||||||
|
%a{href: "javascript:history.back()"}
|
||||||
|
Go Back?
|
||||||
|
|
|
||||||
|
|
@ -6,44 +6,14 @@ class ErrorPageRenderer
|
||||||
def initialize options={}
|
def initialize options={}
|
||||||
@codes = options.fetch :codes, [404, 500]
|
@codes = options.fetch :codes, [404, 500]
|
||||||
@output = options.fetch :output, "public/%s.html"
|
@output = options.fetch :output, "public/%s.html"
|
||||||
@vars = options.fetch :vars, {}
|
|
||||||
@template = options.fetch :template, "errors/error_%s"
|
@template = options.fetch :template, "errors/error_%s"
|
||||||
@layout = options.fetch :layout, "layouts/error_page"
|
@layout = options.fetch :layout, "layouts/error_page"
|
||||||
end
|
end
|
||||||
|
|
||||||
def render
|
def render
|
||||||
@codes.each do |code|
|
@codes.each do |code|
|
||||||
view = build_action_view
|
|
||||||
view.assign @vars.merge(code: code)
|
|
||||||
path = Rails.root.join(@output % code)
|
path = Rails.root.join(@output % code)
|
||||||
File.write path, view.render(template: @template % code, layout: @layout)
|
File.write path, ApplicationController.render(@template % code, layout: @layout, locals: {code: code})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def helpers(&block)
|
|
||||||
@helpers = block
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def build_action_view
|
|
||||||
paths = ::ActionController::Base.view_paths
|
|
||||||
::ActionView::Base.new(paths).tap do |view|
|
|
||||||
view.class_eval do
|
|
||||||
include Rails.application.helpers
|
|
||||||
include Rails.application.routes.url_helpers
|
|
||||||
end
|
|
||||||
view.assets_manifest = build_manifest(Rails.application)
|
|
||||||
view.class_eval(&@helpers) if @helpers
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Internal API from the sprocket-rails railtie, if somebody finds a way to
|
|
||||||
# call it, please replace it. Might need to be updated on sprocket-rails
|
|
||||||
# updates.
|
|
||||||
def build_manifest(app)
|
|
||||||
config = app.config
|
|
||||||
path = File.join(config.paths['public'].first, config.assets.prefix)
|
|
||||||
Sprockets::Manifest.new(app.assets, path, config.assets.manifest)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue