Remove current avatar
# File app/controllers/settings_controller.rb, line 99 def destroy_avatar if current_user.profile_image.present? and current_user.profile_image.destroy flash[:notice] = "Your avatar has been removed." else flash[:alert] = "We were unable to remove your avatar." end redirect_to edit_settings_path end
To edit the user profile information (i.e. educations,awards,positions)
# File app/controllers/settings_controller.rb, line 12 def edit add_breadcrumb "Edit Profile", :edit_settings_path @user = current_user @user.educations.build unless @user.educations.exists? @user.awards.build unless @user.awards.exists? @user.positions.build unless @user.positions.exists? if params[:partial].present? render partial: "#{params[:partial]}", layout: false end end
To build credit card and bank account if not present.
# File app/controllers/settings_controller.rb, line 77 def payment_details @user = current_user @user.credit_cards.build unless @user.credit_cards.exists? @user.bank_accounts.build unless @user.bank_accounts.exists? render layout: false end
Get the current user.
# File app/controllers/settings_controller.rb, line 7 def show @user = current_user end
To update user related information.
# File app/controllers/settings_controller.rb, line 24 def update @user = current_user respond_to do |format| if params[:form_type] == 'change_password' if @user.valid_password?(params[@user.type.downcase.to_sym][:current_password]) || !@user.crypted_password? if params[@user.type.downcase.to_sym][:password] == params[@user.type.downcase.to_sym][:password_confirmation] @user.password = params[@user.type.downcase.to_sym][:password] @user.password_confirmation = params[@user.type.downcase.to_sym][:password_confirmation] @user.valid? if @user.errors[:password].empty? @user.save UserMailer.delay(queue: :mailer).password_update_email(@user) @message = 'Password updated successfully.' format.js else @message = 'Password was not updated.' format.js end else @message = 'Confirm password is not similar to the new password.' format.js end else @message = 'Old password is not valid.' format.js end else if @user.update_attributes(user_params) if params[:type] == 'popover' @message = "#{params[:form_type].titleize} was updated successfully." format.js else message = "#{params[:type].titleize} was updated successfully." if params[:type] format.html { redirect_to edit_settings_path, notice: message} format.js { redirect_via_turbolinks_to edit_settings_path, notice: message} format.json {render json: {}} end else if params[:type] == 'popover' @message = "#{params[:form_type].titleize} was not updated." format.js else message = "#{params[:type].titleize} was not updated." if params[:type] format.html { redirect_to edit_settings_path, notice: message} format.js { redirect_via_turbolinks_to edit_settings_path, notice: message} format.json { render json: @user.errors[:rate_in_cents].present? ? @user.errors[:rate_in_cents].join(', ') : @user.errors.full_messages.join(','), status: :unprocessable_entity } end end end end end
To update the credit card and bank account details of user.
# File app/controllers/settings_controller.rb, line 85 def update_payment_details @user = current_user respond_to do |format| format.js do if @user.update_attributes(user_params) render 'update_payment_details' else render partial: params[:type], locals: {user: @user}, replace: "##{params[:type]}" end end end end