Re: How to display error in view for an instance

Walter Lee Davis
2012-07-03T19:16:54Z

On Jul 3, 2012, at 1:05 PM, renu mehta wrote:

> Walter Davis wrote in post #1067201:
>> On Jul 3, 2012, at 1:59 AM, renu mehta wrote:
>>
>>>
>>> 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.
>>
>> Walter
>
> This is what I get:
>
> #<Member family_member_id: nil, member_first_name: "",
member_last_name:
> "", security_question_answer: nil, created_at: nil, updated_at:
nil,
> member_gender: nil, member_dob: nil, security_question_id: nil,
> native_language: "", family_id: nil, is_child: false,
is_family_head:
> false, member_middle_name: "", member_email: nil, relation_name:
"",
> marital_status: nil>
>
> But nothing about errors. And following code in the loop does not show
> anything.
>
> <% member.errors.full_messages.each do |msg| %>
>
> <%= 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

> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en-US.
>

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.