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.

On 29 May 2008, at 10:53, Divyesh Kumar 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

Frederick C. wrote:

On 29 May 2008, at 10:53, Divyesh Kumar 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
#####
render :action => “show” , :id => session[:user].id
else
#flash[:notice]=“Field marked with asterisk(*) are necessary
or might be wrong”
render :action => “edit_user_info” , :id =>
session[:user].id

    end

But still it is not working:

In model class I am using this…code

validates_uniqueness_of :login, :on => :create

validates_format_of :login, :with => /^\w+$/i,:message => “can only
contain
letters and numbers.”

validates_presence_of :login

validates_presence_of :name , :on => :create

validates_presence_of :password , :on => :create

validates_length_of :login, :within => 3…40

validates_length_of :password, :within => 5…40 , :if=> Proc.new { |u|
u.password.size > 0 && u.password.size < 5 }

validates_confirmation_of :password, :if=> Proc.new { |u|
u.password.size > 0}

validates_presence_of :email

validates_format_of :email, :with =>
/\A([\w.-+]+)@((?:[-a-z0-9]+.)+[a-z]{2,})\z/i ,:message => “cannot
have #,$,%,!,^,&,*… such characters”

validates_presence_of :name, :on => :update

Need ur help

Thanks
Divyesh

On 29 May 2008, at 11:16, Divyesh Kumar 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

On 29 May 2008, at 11:37, Divyesh Kumar 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

Frederick C. wrote:

On 29 May 2008, at 11:37, Divyesh Kumar 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 C. wrote:

On 29 May 2008, at 11:16, Divyesh Kumar 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:
34:
35:
36: <%= error_messages_for ‘@user’%>

On 29 May 2008, at 11:48, Divyesh Kumar wrote:

file

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

Frederick C. wrote:

On 29 May 2008, at 11:48, Divyesh Kumar wrote:

file

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

Thanks very much dude,u are really genious.And next time I’ll take care
of these things.

bye