Error Message is not coming in Validations

Hi,

I am using validations in my website .the problem is that the error
message is not coming while giving wrong inputs or while validations.But
the validations are working fine,what I mean that while giving wrong
inputs the page will not redirect to next page.

I am using the validations in the models and also used

<%= error_messages_for 'model_name'%> in my rhtml file

Thanks and Regards
Divyesh Kumar

Are you sure the validations are working and generating errors on the
object?
If the redirects do not work, the problem is most likely in the
controller. What are you doing there?

Yes the validation are working fine ,if I am giving right inputs
redirect is working fine.

Divyesh Kumar wrote:

Yes the validation are working fine ,if I am giving right inputs
redirect is working fine.

if params[:user]
        user = User.find(session[:user].id)
        if user.update_attributes(params[:user])
#&& ((params[:password]== "" && params[:password_confirmation] == "") ||
(params[:password] != "" && params[:password_confirmation] != ""))
          session[:user] = user
          if params[:picture] != ""
            User.upload_picture(params,session[:user])
          end

           redirect_to :action => "show" , :id => session[:user].id
        else
           flash[:notice]="Field marked with asterisk(*) are necessary
or might be wrong"
           redirect_to :action => "edit_user_info" , :id =>
session[:user].id

As I am using flash to print to print the error message.The problem is
this is not the googd idea for me,I want complete error message for
that.

If you want to get the validation messages you can't use redirect_to (at least not without some extra work) since that throws away the user with errors. You need to use render

Fred

Frederick Cheung wrote:

If you want to get the validation messages you can't use redirect_to
(at least not without some extra work) since that throws away the user
with errors. You need to use render

Fred

Ok, I will take care of this suggestion into my account.

I added like this:

if params[:user]
        user = User.find(session[:user].id)
        if user.update_attributes(params[:user])
          session[:user] = user
          if params[:picture] != ""
            User.upload_picture(params,session[:user])
          end

Frederick Cheung wrote:

If you want to get the validation messages you can't use redirect_to
(at least not without some extra work) since that throws away the
user
with errors. You need to use render

Fred

Ok, I will take care of this suggestion into my account.

You also need to set @user to the user your editing or
error_messages_for 'user' won't know what to display

Fred

Frederick Cheung wrote:

Fred

Ok, I will take care of this suggestion into my account.

You also need to set @user to the user your editing or
error_messages_for 'user' won't know what to display

Fred

This error is cuming after I made changes in controller as well as rhtml
file
NameError in User#edit_user_info

Showing app/views/user/edit_user_info.rhtml where line #36 raised:

`@@user' is not allowed as an instance variable name

Extracted source (around line #36):

33: <form action="edit_user_info" class="genericFormClass" method="post"
enctype="multipart/form-data">
34:
35:
36: <%= error_messages_for '@user'%>

Frederick Cheung wrote:

Fred

Ok, I will take care of this suggestion into my account.

You also need to set @user to the user your editing or
error_messages_for 'user' won't know what to display

Fred

This error is cuming after I made changes in controller as well as rhtml
file
NameError in User#edit_user_info

That's because it should be <%= error_messages_for 'user'%> (check the docs)

Fred

Frederick Cheung wrote:

Fred

This error is cuming after I made changes in controller as well as
rhtml
file
NameError in User#edit_user_info

That's because it should be <%= error_messages_for 'user'%> (check the
docs)

Fred

you are right.I am making the changes but still it is not cuming

U also suggested to change sumthing before,here is ur statement:

You also need to set @user to the user your editing or
error_messages_for 'user' won't know what to display

what is that??

Thanks
Divyesh

Frederick Cheung wrote:

Fred

This error is cuming after I made changes in controller as well as
rhtml
file
NameError in User#edit_user_info

That's because it should be <%= error_messages_for 'user'%> (check
the
docs)

Fred

you are right.I am making the changes but still it is not cuming

U also suggested to change sumthing before,here is ur statement:

You also need to set @user to the user your editing or
error_messages_for 'user' won't know what to display

In the controller you need to use @user in order for the view to be
able to do anything with it
in the view you use error_messages_for 'user'
This should be covered by any introduction to rails type tutorial, you
might find you save a lot of time by doing a little reading rather
than stabbing around in the dark.

Fred