Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added error handling to edit profile otherwise if someone filled in j…

…ust the password for example.

It would redirect to a blank page and not save anything and the user would be very confused no it displays an error message and allows the user
to fix their mistakes.
  • Loading branch information...
commit b2cc14bd7e81918f26b63dacf975912f1ef8d08b 1 parent b3810ce
Paul authored
View
13 app/controllers/users_controller.rb
@@ -25,9 +25,16 @@ def update
params[:user][:crypted_password] = current_user.encrypt(params[:user][:password])
flash[:notice] = t(:password_has_been_changed)
end
- current_user.update_attributes!(params[:user])
- flash[:notice] ||= t(:profile_has_been_updated)
- redirect_to edit_user_path(current_user)
+ respond_to do |format|
+ if current_user.update_attributes(params[:user])
+ current_user.update_attributes!(params[:user])
+ flash[:notice] ||= t(:profile_has_been_updated)
+ redirect_to edit_user_path(current_user)
+ else
+ @themes = Theme.all
+ format.html { render :action => "edit" }
+ end
+ end
end
View
3  app/views/users/edit.html.haml
@@ -1,3 +1,4 @@
+= error_messages_for :user
- form_for current_user, :html => { :multipart => true } do |f|
%table.action-box{:cellpadding => "2", :cellspacing => "0", :width => "100%"}
%thead
@@ -35,7 +36,7 @@
%td.input
= f.text_field "date_display", :size => 10
= f.text_field "time_display", :size => 10
- = link_to "read this for more information", "http://noobkit.com/show/ruby/ruby/ruby-core/time/strftime.html"
+ = link_to "read this for more information", "http://www.wetware.co.nz/blog/2009/07/rails-date-formats-strftime/"
%tr
%td.label{:valign => "top"}
= label_tag "example_time_display", t(:Example_time_display)
Please sign in to comment.
Something went wrong with that request. Please try again.