If there is an error with the submitted password on a form, then both
the password and password confirmation text fields should be highlighted
in red. The default seems to be to highlight only the password field.
Any suggestions on how to correct that? Because rails magically handles
the highlighting, I’m not sure how to intercept that. It looks to me
like I would have to create a partial for the confirmation field. I
tried this:
views/users/new.html.erb:
Sign up
<%= form_for(@user) do |f| %>
<%= render ‘shared/error_messages’ %>
<%= render ‘users/password_confirmation’ %>
views/users/_password_confirmation.html.erb:
<%
css_class = ‘’
@user.errors.any? do |error|
if error.match /password/
css_class = ‘field_with_errors’
end
end
%>
but I got the error:
undefined local variable or method `f’ for
#<#Class:0x00000105023270:0x000001050211c8>
Extracted source (around line #14):
11:
12:
13:
14: <%= f.label :password_confirmation, “Password confirmation:” %>
15:
16:
17: <%= f.password_field :password_confirmation %>
So it looks like a partial creates a new scope, and therefore ‘f’ from
the view page isn’t visible in the partial.