Update + validation error


#1

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:insave_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:intransaction’
/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:intransaction’
/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:inrollback_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:inupdate_attributes!’
app/controllers/players_controller.rb:41:in `update’

why aren’t the validation erros being displayed nicely on update?


#2

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.


#3

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 :slight_smile: Thanks

On Tue, Feb 10, 2009 at 9:29 PM, Maulin pa
<removed_email_address@domain.invalid