Wrap UsersController to not 500 when no params are submitted

This commit is contained in:
Raphael Sofaer 2011-05-19 17:00:53 -07:00
parent c95ce3bd0c
commit ed61c53e09

View file

@ -22,36 +22,37 @@ class UsersController < ApplicationController
def update def update
password_changed = false password_changed = false
u = params[:user] if u = params[:user]
@user = current_user @user = current_user
u.delete(:password) if u[:password].blank? u.delete(:password) if u[:password].blank?
u.delete(:password_confirmation) if u[:password].blank? and u[:password_confirmation].blank? u.delete(:password_confirmation) if u[:password].blank? and u[:password_confirmation].blank?
u.delete(:language) if u[:language].blank? u.delete(:language) if u[:language].blank?
# change email notifications # change email notifications
if u[:email_preferences] if u[:email_preferences]
@user.update_user_preferences(u[:email_preferences]) @user.update_user_preferences(u[:email_preferences])
flash[:notice] = I18n.t 'users.update.email_notifications_changed' flash[:notice] = I18n.t 'users.update.email_notifications_changed'
# change password # change password
elsif u[:current_password] && u[:password] && u[:password_confirmation] elsif u[:current_password] && u[:password] && u[:password_confirmation]
if @user.update_with_password(u) if @user.update_with_password(u)
password_changed = true password_changed = true
flash[:notice] = I18n.t 'users.update.password_changed' flash[:notice] = I18n.t 'users.update.password_changed'
else else
flash[:error] = I18n.t 'users.update.password_not_changed' flash[:error] = I18n.t 'users.update.password_not_changed'
end end
elsif u[:language] elsif u[:language]
if @user.update_attributes(:language => u[:language]) if @user.update_attributes(:language => u[:language])
I18n.locale = @user.language I18n.locale = @user.language
flash[:notice] = I18n.t 'users.update.language_changed' flash[:notice] = I18n.t 'users.update.language_changed'
else else
flash[:error] = I18n.t 'users.update.language_not_changed' flash[:error] = I18n.t 'users.update.language_not_changed'
end end
elsif u[:a_ids] elsif u[:a_ids]
@user.aspects.update_all(:open => false) @user.aspects.update_all(:open => false)
unless u[:a_ids] == ["home"] unless u[:a_ids] == ["home"]
@user.aspects.where(:id => u[:a_ids]).update_all(:open => true) @user.aspects.where(:id => u[:a_ids]).update_all(:open => true)
end
end end
end end