diff --git a/docs/guide/deferred-props.md b/docs/guide/deferred-props.md index d07fe86..fe6c5e4 100644 --- a/docs/guide/deferred-props.md +++ b/docs/guide/deferred-props.md @@ -12,7 +12,15 @@ class UsersController < ApplicationController render inertia: 'Users/Index', props: { users: -> { User.all }, roles: -> { Role.all }, - permissions: InertiaRails.defer(-> { Permission.all }), + permissions: InertiaRails.defer { Permission.all }, + + # Also works with a lambda: + # permissions: InertiaRails.defer(-> { Permission.all }), + + # Also works with a simple value, + # but this way the prop is always evaluated, + # even if not included: + # permissions: InertiaRails.defer(Permission.all), } end end @@ -28,10 +36,12 @@ class UsersController < ApplicationController render inertia: 'Users/Index', props: { users: -> { User.all }, roles: -> { Role.all }, - permissions: InertiaRails.defer(-> { Permission.all }), - teams: InertiaRails.defer(-> { Team.all }, 'attributes'), - projects: InertiaRails.defer(-> { Project.all }, 'attributes'), - tasks: InertiaRails.defer(-> { Task.all }, 'attributes'), + permissions: InertiaRails.defer { Permission.all }, + # using block: + teams: InertiaRails.defer(group: 'attributes') { Team.all }, + # using lambda: + projects: InertiaRails.defer(-> { Project.all }, group: 'attributes'), + tasks: InertiaRails.defer(-> { Task.all }, group: 'attributes'), } end end diff --git a/docs/guide/merging-props.md b/docs/guide/merging-props.md index 694e3a7..06e144f 100644 --- a/docs/guide/merging-props.md +++ b/docs/guide/merging-props.md @@ -14,7 +14,13 @@ class UsersController < ApplicationController _pagy, records = pagy(User.all) render inertia: 'Users/Index', props: { - results: InertiaRails.merge(-> { records }), + results: InertiaRails.merge(records), + + # Also works with block: + # results: InertiaRails.merge { records }, + + # Also works with a lambda: + # results: InertiaRails.merge(-> { records }), } end end @@ -30,7 +36,7 @@ class UsersController < ApplicationController def index render inertia: 'Users/Index', props: { - results: InertiaRails.defer(-> { pagy(User.all)[1] }).merge, + results: InertiaRails.defer { pagy(User.all)[1] }.merge, } end end diff --git a/docs/guide/partial-reloads.md b/docs/guide/partial-reloads.md index 209964c..4e88cc6 100644 --- a/docs/guide/partial-reloads.md +++ b/docs/guide/partial-reloads.md @@ -170,7 +170,15 @@ Additionally, Inertia provides an `InertiaRails.optional` method to specify that class UsersController < ApplicationController def index render inertia: 'Users/Index', props: { - users: InertiaRails.optional(-> { User.all }), + users: InertiaRails.optional { User.all }, + + # Also works with a lambda: + # users: InertiaRails.optional(-> { User.all }), + + # Also works with a simple value, + # but this way the prop is always evaluated, + # even if not included: + # users: InertiaRails.optional(User.all), } end end @@ -186,6 +194,12 @@ class UsersController < ApplicationController def index render inertia: 'Users/Index', props: { users: InertiaRails.always(User.all), + + # Also works with block: + # users: InertiaRails.optional { User.all }, + + # Also works with a lambda: + # users: InertiaRails.optional(-> { User.all }), } end end @@ -210,7 +224,7 @@ class UsersController < ApplicationController # NEVER included on standard visits # OPTIONALLY included on partial reloads # ONLY evaluated when needed - users: InertiaRails.optional(-> { User.all }), + users: InertiaRails.optional { User.all }, # ALWAYS included on standard visits # ALWAYS included on partial reloads