instance method
strict_locals!
Ruby on Rails 7.2.3
Since v7.1.6Signature
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 367
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 367
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Template