Skip to content

Commit 862f402

Browse files
authored
Merge pull request rails#52209 from bensheldon/strict-local-assigns-defaults
Document undefined `local_assigns` when using Strict Locals with defaults
2 parents 716e4a7 + fe03a19 commit 862f402

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

guides/source/action_view_overview.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,16 @@ line in the partial.
689689
CAUTION: Only keyword arguments are supported. Defining positional or block
690690
arguments will raise an Action View Error at render-time.
691691

692+
The `local_assigns` method does not contain default values specified in the
693+
`local:` magic comment. To access a local variable with a default value that
694+
is named the same as a reserved Ruby keyword, like `class` or `if`, the values
695+
can be accessed through `binding.local_variable_get`:
696+
697+
```erb
698+
<%# locals: (class: "message") %>
699+
<div class="<%= binding.local_variable_get(:class) %>">...</div>
700+
```
701+
692702
Layouts
693703
-------
694704

0 commit comments

Comments
 (0)