I have a partial _errors.html.haml
to display the form errors in my application. The code inside the partial:
.errors
%ul
- errors.full_messages.each do |message|
%li= message
I am rendering the partial from projects/new.html.haml as
= render 'shared/errors', locals: { errors: @project.errors } if @project.errors.any?
The errors partial resides in views/shared
directory.
But I get an error when I try to render the errors partial.
undefined local variable or method errors' for #<#<Class:0x0055895405bbc0> :0x00558951a80fe0>
If I change the rendering line to
= render 'shared/errors', errors: @project.errors if @project.errors.any?
it works. Why doesn't using locals
work in this case?