inertiajs / inertia-rails

The Rails adapter for Inertia.js.
https://inertiajs.com
MIT License
529 stars 43 forks source link

Add an inertia_partial? method onto request #33

Closed ledermann closed 4 years ago

ledermann commented 4 years ago

Similar to #24 this PR adds #inertia_partial? to the request. It checks the header for X-Inertia-Partial-Data to distinguish between a full or partial request.

Example use case: In an application showing posts, I want to Increase the post's view counter for full requests only. Code from the controller:

class PostsController < ApplicationController 
  after_action :increase_view_count, only: [ :show ]
  # ...

  private

  def increase_view_count
    @post.punch(request) unless request.inertia_partial?
  end
end
BrandonShar commented 4 years ago

I haven't used this feature of inertia yet, but this makes good sense to me. Thanks!