instance method locals_code

Ruby on Rails 7.0.10

Since v5.2.8.1 Private

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

Signature

locals_code()

No documentation comment.

Source
# File actionview/lib/action_view/template.rb, line 325
      def locals_code
        # Only locals with valid variable names get set directly. Others will
        # still be available in local_assigns.
        locals = @locals - Module::RUBY_RESERVED_KEYWORDS
        deprecated_locals = locals.grep(/\A@+/)
        if deprecated_locals.any?
          ActiveSupport::Deprecation.warn(<<~MSG)
            Passing instance variables to `render` is deprecated.
            In Rails 7.1, #{deprecated_locals.to_sentence} will be ignored.
          MSG
          locals = locals.grep(/\A@?(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
        else
          locals = locals.grep(/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/)
        end

        # Assign for the same variable is to suppress unused variable warning
        locals.each_with_object(+"") { |key, code| code << "#{key} = local_assigns[:#{key}]; #{key} = #{key};" }
      end

Defined in actionview/lib/action_view/template.rb line 325 · 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