# Error\_messages\_for not working

**URL:** <https://www.ruby-forum.com/t/error-messages-for-not-working/99579>\
**Category:** Rails\
**Created:** [July 24, 2006, 9:10am UTC](https://www.ruby-forum.com/t/error-messages-for-not-working/99579 "2006-07-24T09:10:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [July 24, 2006, 9:10am UTC](https://www.ruby-forum.com/t/error-messages-for-not-working/99579/1 "2006-07-24T09:10:05Z")

</div>

I have the following code and I am not able to get it working. The error  
message is not coming on the top, it is just getting displayed on a  
different page if I dont have the rescue block commented at the bottom.

Model: user.rb  
require “digest/sha1”

class User \< ActiveRecord::Base

validates\_presence\_of :eaddress, :fname, :passwd, :pcode, :country,  
:day, :year, :month, :gender,  
:agreement

validates\_confirmation\_of :passwd  
validates\_uniqueness\_of :eaddress  
validates\_length\_of :eaddress, :within =\> 6…255  
validates\_numericality\_of :pcode

end

View: index.rhtml  
…

| Quick Register! |
| 

\<%= form\_tag(:controller =\> “login”, :action =\> “register\_user”) %\>  
\<%= error\_messages\_for(:user) %\>  
…

Controller: community\_controller.rb  
def register\_user

# begin

@user = User.new(params[“user”])  
@user.passwd = User.hash\_password(params[“user”][“passwd”])  
if @user.save!  
redirect\_to(:controller =\> “profile”, :action =\> “createprofile”)  
else  
render(:template =\> “login/index”)  
end

# rescue Exception =\> exc

# flash[:notice] = “General error in registration = #{exc.message}”

# render(:template =\> “login/index”)

# return

# end

end

 |

---

<div class="post-metadata">

**Author:** ![vinoddas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/278dde/32.png) [@vinoddas](https://www.ruby-forum.com/u/vinoddas)\
**Post date:** [July 24, 2006, 9:37am UTC](https://www.ruby-forum.com/t/error-messages-for-not-working/99579/2 "2006-07-24T09:37:05Z")

</div>

On 7/24/06, Vinod K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> validates\_presence\_of :eaddress, :fname, :passwd, :pcode, :country,
> 
> \<%= error\_messages\_for(:user) %\>  
> …
> 
> Controller: community\_controller.rb  
> def register\_user
> 
> # begin
> 
> @user = User.new(params[“user”])  
> @user.passwd = User.hash\_password(params[“user”][“passwd”])

The @user.save! is the destructive form. If the user does not save an  
error  
is raised. Hence the requirement for a rescue clause.

Use @user.save instead. This should then become  
if @user.save

if @user.save!
