How can we display the errors in a view if that view contains one
instance of type member and an array also of instances from the same
model. In my app I have a form which accepts a member data for
registration for a family on the top and at the end of the screen in the
same form I accept the data for the rest of the family members which
also belong to the same model. After the validation I get the errors for
‘@member’ but not the ‘@familt_members’. @member is created as
instance in the array?
What do you see if you iterate over the members of the array, like this
(in a view, just for debugging purposes)?
<%- @member_list.each do |member| %>
<%= member.inspect %>
<%- end %>
I am guessing that each member will carry its own hash of errors, and
you should see them when you do this. Then it’s just a matter of
iterating them in your view to build the error list per member.
instance in the array?
What do you see if you iterate over the members of the array, like this
(in a view, just for debugging purposes)?
<%- @member_list.each do |member| %>
<%= member.inspect %>
<%- end %>
I am guessing that each member will carry its own hash of errors, and
you should see them when you do this. Then it’s just a matter of
iterating them in your view to build the error list per member.
<%- end %>
“”, security_question_answer: nil, created_at: nil, updated_at: nil, <%= msg %>
<% end %>
At this point in the cycle, have you already tried to save these
members? Or are they being saved through an association? I don’t think
the errors are populated on any AR object until you actually try to
save, because those validations only run within the save cycle.
Walter
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.