Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Railsのエラーページ運用について本気出して考えてみた

Yuichi Goto
August 29, 2015

 Railsのエラーページ運用について本気出して考えてみた

TokyuRuby会議09(2015/08/29)

Yuichi Goto

August 29, 2015
Tweet

More Decks by Yuichi Goto

Other Decks in Technology

Transcript

  1. About me [1] pry(main)> me => { twitter:'@_yasaichi', github: 'yasaichi',

    splatoon: nil, blog: 'http://web-salad.hateblo.jp' }
  2. 1. Register template engine # config/initializers/assets.rb # Use Haml Rails.application.assets.register_engine('.haml',

    Tilt::HamlTemplate) # Use Slim # slim-rails 3.0.1 Ҏ߱Ͱ͸ෆཁ Rails.application.assets.register_engine('.slim', Slim::Template)
  3. 2. Write error pages / app/assets/templates/404.html.slim doctype html html head

    title TestApp = stylesheet_link_tag 'error', media: 'all' body p 404.html # config/initializers/assets.rb Rails.application.config.assets.precompile << 'error.css'
  4. 3. After hook for precompile # lib/tasks/after_precompile.rb Rake::Task['assets:precompile'].enhance do logger

    = Logger.new(STDOUT) %w(404 422 500 503).each do |status_code| pattern = Rails.public_path.join("assets/#{status_code}-*.html") src = Pathname.glob(pattern).sort_by { |path| path.mtime }.last next if src.nil? dest = Rails.public_path.join("#{status_code}.html") logger.info("mv #{src} to #{dest}") FileUtils.mv(src, dest) end end digestΛऔΓআ͍ͯ
 public/ҎԼʹҠ͢
  5. 4. Precompile on deploy % RAILS_ENV=production rake assets:precompile I, [2015-08-28T01:07:37.256609

    #39050] INFO -- : mv /path/to/public /assets/404-f26c195d5a2d8b404e020dc08dcfc5856940832aff1906b2eadc584a cbbc8735.html to /path/to/public/404.html <!-- public/404.html —> <!DOCTYPE html> <html> <head> <title>TestApp</title><link rel="stylesheet" media="all" href="/assets/ error-d46af6b953e1af51c1cc79e736904476e9c33f651b6264f2973ec7690b894112.css" /> </head> <body> <p>404.html</p> </body> </html>
  6. Strong points • ςϯϓϨʔτΤϯδϯ͕࢖͑Δ • Sprockets::Rails::HelperͰ࣮૷͞Ε͍ͯΔ
 assetؔ࿈ͷhelper͕࢖͑ΔʢҎԼൈਮʣ asset_path, asset_url, audio_path,

    audio_tag, audio_url, content_tag, favicon_link_tag, font_path, font_url, image_path, image_tag, image_url, javascript_include_tag, javascript_path, javascript_url, path_to_asset, stylesheet_link_tag, stylesheet_path, stylesheet_url, tag, video_path, video_tag, video_url
  7. Overview gem 'gakubuchi' gem 'haml-rails' % rails generate gakubuchi:install create

    config/initializers/gakubuchi.rb create app/assets/templates % touch app/assets/templates/foo.html.haml % rake assets:precompile % cd public && ls *.html 404.html 422.html 500.html foo.html Կ΋ઃఆͯ͠ͳ͍ ͷʹͰ͖ͨʂ