Sha256: 485ab0a6a90aa18386a9978912cc6ad0266e4e8d1adb641542ab08b8a1da48cd

Contents?: true

Size: 1.13 KB

Versions: 31

Compression:

Stored size: 1.13 KB

Contents

# Turbo frame requests are requests made from within a turbo frame with the intention of replacing the content of just
# that frame, not the whole page. They are automatically tagged as such by the Turbo Frame JavaScript, which adds a
# <tt>Turbo-Frame</tt> header to the request. When that header is detected by the controller, we ensure that any
# template layout is skipped (since we're only working on an in-page frame, thus can skip the weight of the layout), and
# that the etag for the page is changed (such that a cache for a layout-less request isn't served on a normal request
# and vice versa).
#
# This is merely a rendering optimization. Everything would still work just fine if we rendered everything including the layout.
# Turbo Frames knows how to fish out the relevant frame regardless.
#
# This module is automatically included in <tt>ActionController::Base</tt>.
module Turbo::Frames::FrameRequest
  extend ActiveSupport::Concern

  included do
    layout -> { false if turbo_frame_request? }
    etag { :frame if turbo_frame_request? }
  end

  private
    def turbo_frame_request?
      request.headers["Turbo-Frame"].present?
    end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
turbo-rails-0.5.10 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.9 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.8 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.7 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.6 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.5 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.4 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.3 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.2 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.1 app/controllers/turbo/frames/frame_request.rb
turbo-rails-0.5.0 app/controllers/turbo/frames/frame_request.rb