From 8fa4feb469a6ffa692b96d90ca91607b72943934 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 21 Dec 2021 23:56:57 +0100 Subject: [PATCH] Add endpoint for updating profile --- app/controllers/user_controller.rb | 14 ++++++++++++-- app/views/settings/_profile.haml | 2 +- config/routes.rb | 1 + db/schema.rb | 2 -- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 0cb802cb..11d371df 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -28,8 +28,7 @@ class UserController < ApplicationController end def update - user_attributes = params.require(:user).permit(:display_name, :motivation_header, :website, :show_foreign_themes, :location, :bio, - :profile_picture_x, :profile_picture_y, :profile_picture_w, :profile_picture_h, + user_attributes = params.require(:user).permit(:show_foreign_themes, :profile_picture_x, :profile_picture_y, :profile_picture_w, :profile_picture_h, :profile_header_x, :profile_header_y, :profile_header_w, :profile_header_h, :profile_picture, :profile_header) if current_user.update_attributes(user_attributes) text = t('flash.user.update.text') @@ -41,6 +40,17 @@ class UserController < ApplicationController end redirect_to edit_user_profile_path end + + def update_profile + profile_attributes = params.require(:profile).permit(:display_name, :motivation_header, :website, :location, :description) + + if current_user.profile.update_attributes(profile_attributes) + flash[:success] = t('flash.user.update.text') + else + flash[:error] = t('flash.user.update.error') + end + redirect_to edit_user_profile_path + end # endregion # region Privacy settings diff --git a/app/views/settings/_profile.haml b/app/views/settings/_profile.haml index 4a0f3389..eecd4bf7 100644 --- a/app/views/settings/_profile.haml +++ b/app/views/settings/_profile.haml @@ -48,7 +48,7 @@ .card .card-body - = bootstrap_form_for(current_user.profile, url: { action: :edit }, html: { multipart: true }, method: :patch) do |f| + = bootstrap_form_for(current_user.profile, url: { action: :update_profile }, html: { multipart: true }, method: :patch) do |f| = f.text_field :display_name, label: t('views.settings.profile.displayname') diff --git a/config/routes.rb b/config/routes.rb index dc67cee9..35d23bee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -62,6 +62,7 @@ Rails.application.routes.draw do match '/settings/profile', to: 'user#edit', via: 'get', as: :edit_user_profile match '/settings/profile', to: 'user#update', via: 'patch', as: :update_user_profile + match '/settings/profile_info', to: 'user#update_profile', via: 'patch', as: :update_user_profile_info match '/settings/theme', to: 'user#edit_theme', via: 'get', as: :edit_user_theme match '/settings/theme', to: 'user#update_theme', via: 'patch', as: :update_user_theme diff --git a/db/schema.rb b/db/schema.rb index 8509a89b..eb8141ef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -137,9 +137,7 @@ ActiveRecord::Schema.define(version: 2021_12_19_153054) do t.datetime "created_at" t.datetime "updated_at" t.integer "answer_count", default: 0, null: false - t.datetime "discarded_at" t.boolean "direct", default: false, null: false - t.index ["discarded_at"], name: "index_questions_on_discarded_at" t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at" end