Add endpoint for updating profile

This commit is contained in:
Karina Kwiatek 2021-12-21 23:56:57 +01:00
parent 00496a1596
commit 8fa4feb469
4 changed files with 14 additions and 5 deletions

View File

@ -28,8 +28,7 @@ class UserController < ApplicationController
end end
def update def update
user_attributes = params.require(:user).permit(:display_name, :motivation_header, :website, :show_foreign_themes, :location, :bio, user_attributes = params.require(:user).permit(:show_foreign_themes, :profile_picture_x, :profile_picture_y, :profile_picture_w, :profile_picture_h,
: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) :profile_header_x, :profile_header_y, :profile_header_w, :profile_header_h, :profile_picture, :profile_header)
if current_user.update_attributes(user_attributes) if current_user.update_attributes(user_attributes)
text = t('flash.user.update.text') text = t('flash.user.update.text')
@ -41,6 +40,17 @@ class UserController < ApplicationController
end end
redirect_to edit_user_profile_path redirect_to edit_user_profile_path
end 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 # endregion
# region Privacy settings # region Privacy settings

View File

@ -48,7 +48,7 @@
.card .card
.card-body .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') = f.text_field :display_name, label: t('views.settings.profile.displayname')

View File

@ -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#edit', via: 'get', as: :edit_user_profile
match '/settings/profile', to: 'user#update', via: 'patch', as: :update_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#edit_theme', via: 'get', as: :edit_user_theme
match '/settings/theme', to: 'user#update_theme', via: 'patch', as: :update_user_theme match '/settings/theme', to: 'user#update_theme', via: 'patch', as: :update_user_theme

View File

@ -137,9 +137,7 @@ ActiveRecord::Schema.define(version: 2021_12_19_153054) do
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.integer "answer_count", default: 0, null: false t.integer "answer_count", default: 0, null: false
t.datetime "discarded_at"
t.boolean "direct", default: false, null: false 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" t.index ["user_id", "created_at"], name: "index_questions_on_user_id_and_created_at"
end end