From 4b21bda4fbce0997e7ac7dba14949c7165bd85b3 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 3 Jun 2025 04:27:40 +0300 Subject: [PATCH] Add profile section controller parent class --- .../profiles/descriptions_controller.rb | 24 +++--------------- .../profiles/profile_sections_controller.rb | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 app/controllers/profiles/profile_sections_controller.rb diff --git a/app/controllers/profiles/descriptions_controller.rb b/app/controllers/profiles/descriptions_controller.rb index 262048be3..6a6b9a99f 100644 --- a/app/controllers/profiles/descriptions_controller.rb +++ b/app/controllers/profiles/descriptions_controller.rb @@ -1,18 +1,8 @@ module Profiles - class DescriptionsController < ApplicationController - layout "site" + class DescriptionsController < ProfileSectionsController + private - before_action :authorize_web - before_action :set_locale - - authorize_resource :class => :profile - - before_action :check_database_readable - before_action :check_database_writable, :only => [:update] - - def show; end - - def update + def update_profile social_links_params = params.permit(:user => [:social_links_attributes => [:id, :url, :_destroy]]) current_user.assign_attributes(social_links_params[:user]) @@ -39,13 +29,7 @@ module Profiles current_user.home_lon = params[:user][:home_lon] current_user.home_location_name = params[:user][:home_location_name] - if current_user.save - flash[:notice] = t ".success" - redirect_to user_path(current_user) - else - flash.now[:error] = t ".failure" - render :show - end + current_user.save end end end diff --git a/app/controllers/profiles/profile_sections_controller.rb b/app/controllers/profiles/profile_sections_controller.rb new file mode 100644 index 000000000..3ab17616d --- /dev/null +++ b/app/controllers/profiles/profile_sections_controller.rb @@ -0,0 +1,25 @@ +module Profiles + class ProfileSectionsController < ApplicationController + layout "site" + + before_action :authorize_web + before_action :set_locale + + authorize_resource :class => :profile + + before_action :check_database_readable + before_action :check_database_writable, :only => [:update] + + def show; end + + def update + if update_profile + flash[:notice] = t ".success" + redirect_to user_path(current_user) + else + flash.now[:error] = t ".failure" + render :show + end + end + end +end -- 2.39.5