Forum: Ruby on Rails update + validation error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
44999b12bbad1b498252b3ac60c3ab0f?d=identicon&s=25 Maulin pa (mpathare)
on 2009-02-11 03:13
I have a Player model with some validations. I am using a partial form
to create and update player info. I have the following like in the view

<%= error_messages_for 'player' %>

On create the validation errors are correctly displayed, but if a
validation error fails update, I get an ugly stack trace error that
looks like this

validation failed: Last name can't be blank

RAILS_ROOT: /home/maulin/projects/sports_ladder
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/validations.rb:1021:in
`save_without_dirty!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/dirty.rb:87:in
`save_without_transactions!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:150:in
`save!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in
`transaction'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:129:in
`transaction'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:138:in
`transaction'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:150:in
`save!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:158:in
`rollback_active_record_state!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/transactions.rb:150:in
`save!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2476:in
`update_attributes!'
app/controllers/players_controller.rb:41:in `update'

why aren't the validation erros being displayed nicely on update?
44999b12bbad1b498252b3ac60c3ab0f?d=identicon&s=25 Maulin pa (mpathare)
on 2009-02-11 03:29
> why aren't the validation erros being displayed nicely on update?

I was able to figure this out...If the record was not successfully
audated because of a validation error, I needed to render :action =>
:edit.

It now shows the errors nicely.
23ae9e75998020bacd139c7a5da311fc?d=identicon&s=25 David Herman (Guest)
on 2009-02-11 04:11
(Received via mailing list)
I think this is a good example of how we should behave on a mailing
list...
too many people figure out an answer and never respond back :)  Thanks

On Tue, Feb 10, 2009 at 9:29 PM, Maulin pa
<rails-mailing-list@andreas-s.net
This topic is locked and can not be replied to.