instance method local_assigns

Ruby on Rails 7.0.10

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Returns a hash with the defined local variables.

Given this sub template rendering:

<%= render "shared/header", { headline: "Welcome", person: person } %>

You can use local_assigns in the sub templates to access the local variables:

local_assigns[:headline] # => "Welcome"
Source
# File actionview/lib/action_view/template.rb, line 103
    eager_autoload do
      autoload :Error
      autoload :RawFile
      autoload :Renderable
      autoload :Handlers
      autoload :HTML
      autoload :Inline
      autoload :Sources
      autoload :Text
      autoload :Types
    end

Defined in actionview/lib/action_view/template.rb line 103 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Template

Type at least 2 characters to search.

↑↓ navigate · open · esc close