instance method strict_locals!

Ruby on Rails 7.1.6

Since v7.1.6

Available in: v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

strict_locals!()

This method is responsible for marking a template as having strict locals which means the template can only accept the locals defined in a magic comment. For example, if your template acceps the locals title and comment_count, add the following to your template file:

<%# locals: (title: "Default title", comment_count: 0) %>

Strict locals are useful for validating template arguments and for specifying defaults.

Source
# File actionview/lib/action_view/template.rb, line 343
    def strict_locals!
      if @strict_locals == NONE
        self.source.sub!(STRICT_LOCALS_REGEX, "")
        @strict_locals = $1

        return if @strict_locals.nil? # Magic comment not found

        @strict_locals = "**nil" if @strict_locals.blank?
      end

      @strict_locals
    end

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