I''ve got an odd case where the certain models doesn''t want to
either
update and/or create a new one. The problem, as I later found out,
was due to validation errors (which is great, actually) except for
some reason, <%= error_messages_for ''some_model'' %>
doesn''t print
anything. This is problematic, because as it turns out, one of my
user models won''t update because I have to provide a new password,
each time.
Long story short, I have two problems:
error_messages_for method doesn''t seem to print anything. Does this
have to do with how I''m bringing up the code in my controller? A
typical update method in my controllers look like this:
-------------------------------------
def edit_user
@user=User.find(params[:id])
end
def update_user
@user=User.find(params[:id])
if !params[:user]
flash[:notice]=nil
render :action => ''edit_user''
elsif @user.update_attributes(params[:user])
flash[:notice] = "#{@user.username} was successfully updated."
redirect_to #someplace.
else
flash[:notice]="Failed to update user. Please try again."
render :action => ''edit_user''
end
end
--------------------------------------
Does flash[:notice] prevent error_messages_for from showing up? Last
time I tried taking off that line, error_messages_for gave me nothing!
The second problem is how do I update only portions of the model
(preferably some method that accepts an :except parameter) given by
the text field in the view forms that''s supposed to update the model.
I''m currently using the method update_attributes(params[:user]), and I
DON''T want it to update the password if the password field is empty,
which this method seems to be doing.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---