Following code:
<%= render 'shared/error_messages', f.object %>
where f.object is instance of a class called ‘User’.
in an erb file is raising an error about not finding method ‘keys’ in the User object.
What’s going on?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The second parameter to render, locals is a map that specifies the variables that would be available in the partial that will be rendered. Api Doc:
http://apidock.com/rails/ActionView/Template/render
Here, we are passing a User instance instead of the map Rails is expecting. When executing the code to render the partial, Rails is trying to use the User object as a map, hence the error about not finding the method ‘keys’.
What I really needed was this –
where object is a variable the _error_messages.html.erb partial is expecting. This resolved the error.