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
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?
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
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
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
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.