Dashboard
1. Gem better_erros:
Gem better_errors được dùng để thay thế trang hiển thị lỗi mặc định của Rails với nhiều chức năng hữu ích hơn
a. Default error page:
Trang hiển thị lỗi mặc định của Rails gồm các phấn như sau
Dòng code gay ra lỗi
Stack trace
Error response
Shell để run test code
b. Install gem better_erors:
c. Better errors page:
Trang hiển thị lỗi của better_errors gồm các phần như sau
Full stack trace
Source code tương ứng với mỗi stack trace
Variable được gọi và giá trị của variable trong stack trace
Shell ứng với mỗi stack trace
Link để mở source code của stack trace với editor tương ứng
Link source code demo: https://github.com/thanhlt-1007/demo_better_errors
2. Gem exception_handler:
Gem exception_handler được dùng để thay thế trang hiển thị lỗi mặc định của Rails với dynamic views có thể custom được
a. Install gem exception_handler:
b. Exception handler page:
Trang hiển thị lỗi của exception_handler
Các option khác để custom exception handler:
i: DB:
Sau khi install gem exception_handler ta có thể chạyrails db:migrate
Gem exception_handler sẽ update file schema, tạo table errors có nội dung như sau# db/schema.rb
create_table "errors", force: :cascade do |t|
t.text "class_name"
t.text "status"
t.text "message"
t.text "trace"
t.text "target"
t.text "referrer"
t.text "params"
t.text "user_agent"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Khi xảy ra lỗi, gem exception_handler sẽ insert record vào table errors
Tạo model Error ứng với table errors
class Error < ApplicationRecord
end
ii. Views (layouts, locale):
Màn hình error của gem exception_handler được generate bởi action show của ExceptionHandler::ExceptionsController
-Bạn có thể check source code tại đây
Để custom layout, bạn có thể overrite lại action show của ExceptionHandler::ExceptionsController hoặc thay đổi layout và locale
Custom locale
Custom layout
Theo mặn định thì error page của gem exception_handler sẽ sử dụng layout layouts/exception
Bạn có thể check tại đây
Bạn có thể overrite lại file layout này
Hoặc sử dụng config để quy định layout theo 1 trong các hướng sau
Sử dụng layout được quy định bởi ApplicationController
config. exception_handler = {
exceptions: {
all: { layout: nil }
}
}
Quy định layout riêng cho từng lại exception theo HTTP status
config. exception_handler = {
exceptions: {
all: { layout: 'exception' } ,
5 xx: { layout: 'server_error_exception' } ,
4 xx: { layout: 'client_error_exception' } ,
500 : { layout: 'internal_server_error_exception' }
}
}
iii. Generators:
Source: https://viblo.asia/p/mot-so-gem-lien-quan-den-hien-thi-loi-va-custom-error-page-cua-rails-V3m5WdRvKO7
Random articles
Cài đặt môi trường Pentest Android trên Windows (Phần 1)
Một trong số các vấn đề khó nhất với những ai muốn tìm hiểu về Kiểm thử xâm nhập ứng dụng Android (Pentesting Android applications) là cách cài đặt môi trường kiểm thử. Kiểm thử xâm nhập ứng dụng di động cũng có nhiều điểm tương tự như Kiểm thử xâm nhập ứng dụng web, tuy nhiên việc cài đặt môi trường cho việc kiểm thử xâm nhập ứng dụng di động lại khó hơn nhiều.
Đối với...
pentest
1624
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.