8000 Strict locals when rendering from controllers · Issue #56682 · rails/rails · GitHub
[go: up one dir, main page]

8000
Skip to content

Strict locals when rendering from controllers #56682

@yxhuvud

Description

@yxhuvud

Ok, so this is more an inconsistency, and I don't know if it is intentional or if it is accidental. It certainly expands the scope of strict locals a bit. But I found no github issues surrounding it, so at the worst there will be a closed issue saying it is not wanted that someone can find.

Steps to reproduce

in NONPARTIAL view, eg show.html.erb:

<%# locals: ( foo:, bar: ) %>

In controller:
render locals: { foo: :baz}

In test :

render(locals: {foo: :baz})

Expected behavior

So what I expect is an error in the controller when doing the render - if I declare I want locals I want them to be enforced. Alternatively an error from the view saying they are not working could be reasonable behavior. Silently ignoring them seems the worst choice by far.

I also prefer to have the error (whichever!) in the test.

Actual behavior

Controller simply ignore the directive about locals being required.

Tests DO enforce them (and this may be an rspec-ism - depending on response I may follow up with an issue for more consistency over on the rspec side).

System configuration

Rails version:
8.1.1

Ruby version:
4.0.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0