# Send form validation errors through redirect?

**URL:** <https://www.ruby-forum.com/t/send-form-validation-errors-through-redirect/190791>\
**Category:** Rails\
**Created:** [June 28, 2010, 8:04am UTC](https://www.ruby-forum.com/t/send-form-validation-errors-through-redirect/190791 "2010-06-28T08:04:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![victor123789](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/f0a364/32.png) [@victor123789](https://www.ruby-forum.com/u/victor123789)\
**Post date:** [June 28, 2010, 8:04am UTC](https://www.ruby-forum.com/t/send-form-validation-errors-through-redirect/190791/1 "2010-06-28T08:04:20Z")

</div>

Hi,

I’m new at this, how do I send the errors that one would get from a  
standard ruby scaffold generator on a form that is attempted to POST  
incorrectly? With all the beautiful formatting etc…

Right now I have this:

# POST /environments

# POST /environments.xml

def create  
@project = Project.find(params[:project\_id])  
# @environment = Environment.new(params[:environment])  
@environment = @project.environments.create(params[:environment])  
if @environment.save  
redirect\_to project\_path(@project), :notice =\> ‘Saved’  
else  
redirect\_to project\_path(@project), :notice =\> ‘Error’  
end

And it works, but I only get what I define: “Error”, whereas I would  
like to get the explicit errors that the validators are catching…  
something like: (does not work)

# POST /environments

# POST /environments.xml

def create  
@project = Project.find(params[:project\_id])  
# @environment = Environment.new(params[:environment])  
@environment = @project.environments.create(params[:environment])  
if @environment.save  
redirect\_to project\_path(@project), :notice =\> ‘Saved’  
else  
rescue ActiveRecord::RecordInvalid =\> invalid  
@error = invalid.record.errors  
end  
redirect\_to project\_path(@project), :notice =\> @error  
end

Any suggestions?
