merging model validation errors
May 14, 2007 | In: ruby
Here is a simple chunk of code that I find very useful when working with multiple objects in one form that leverage the Rails model validation functions.
In this example we see how to merge validation errors for more then one object so they can be displayed with the error_messages_for helper.
if @user.update_attributes(params[:user])
flash[:notice] = "Account Updated"
else
flash[:notice] = "Account Updated Failed"
@user.profile.errors.each do |attribute, error|
@user.errors.add(attribute, error)
end
end











Latest comments