Can anyone explain why this happens?

    mybox:$ ruby script/console
    Loading development environment (Rails 2.3.5)
    >> foo = Foo.new
    => #<Foo id: nil, customer_id: nil, created_at: nil, updated_at:
nil>
    >> bar = Bar.new
    => #<Bar id: nil, bundle_id: nil, alias: nil, real: nil, active:
true, list_type: 0, body_record_active: false, created_at: nil,
updated_at: nil>
    >> bar.save
    => false
    >> bar.errors.each_full { |msg| puts msg }
    Real can't be blank
    Real You must supply a valid email
    => ["Real can't be blank", "Real You must supply a valid email"]

So far that is perfect, that is what i want the error message to read.
Now for more:

    >> foo.bars << bar
    => [#<Bar id: nil, bundle_id: nil, alias: nil, real: nil, active:
true, list_type: 0, body_record_active: false, created_at: nil,
updated_at: nil>]
    >> foo.save
    => false
    >> foo.errors.to_xml
    => "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<errors>\n
<error>Bars is invalid</error>\n</errors>\n"

That is what I can't figure out. Why am I getting Bars is invalid
versus the error messages displayed above, ["Real can't be blank",
"Real you must supply a valid email"]  etc.

My controller simply has a respond_to method with the following in it:

     format.xml  { render :xml => @foo.errors, :status
=> :unprocessable_entity }

How do I have this output the real error messages so the user has some
insight into what they did wrong? How do I write my render method in
my controller to show all of the appropriate error messages? And more
important, what will my xml builder view look?

-- 
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to