Move profile picture actions to `Settings::ProfilePictureController`
This commit is contained in:
parent
efa0048c87
commit
8141db2ca7
|
@ -6,20 +6,6 @@ class Settings::ProfileController < ApplicationController
|
||||||
def edit; end
|
def edit; end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
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(user_attributes)
|
|
||||||
text = t(".success")
|
|
||||||
text += t(".notice.profile_picture") if user_attributes[:profile_picture]
|
|
||||||
text += t(".notice.profile_header") if user_attributes[:profile_header]
|
|
||||||
flash[:success] = text
|
|
||||||
else
|
|
||||||
flash[:error] = t(".error")
|
|
||||||
end
|
|
||||||
redirect_to edit_user_profile_path
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_profile
|
|
||||||
profile_attributes = params.require(:profile).permit(:display_name, :motivation_header, :website, :location, :description, :anon_display_name)
|
profile_attributes = params.require(:profile).permit(:display_name, :motivation_header, :website, :location, :description, :anon_display_name)
|
||||||
|
|
||||||
if current_user.profile.update(profile_attributes)
|
if current_user.profile.update(profile_attributes)
|
||||||
|
@ -27,6 +13,7 @@ class Settings::ProfileController < ApplicationController
|
||||||
else
|
else
|
||||||
flash[:error] = t(".error")
|
flash[:error] = t(".error")
|
||||||
end
|
end
|
||||||
redirect_to edit_user_profile_path
|
|
||||||
|
redirect_to settings_profile_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::ProfilePictureController < ApplicationController
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def update
|
||||||
|
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(user_attributes)
|
||||||
|
text = t(".success")
|
||||||
|
text += t(".notice.profile_picture") if user_attributes[:profile_picture]
|
||||||
|
text += t(".notice.profile_header") if user_attributes[:profile_header]
|
||||||
|
flash[:success] = text
|
||||||
|
else
|
||||||
|
flash[:error] = t(".error")
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to settings_profile_path
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
.card
|
.card
|
||||||
.card-body
|
.card-body
|
||||||
= bootstrap_form_for(current_user, url: { action: :edit }, html: { multipart: true }, method: :patch) do |f|
|
= bootstrap_form_for(current_user, url: settings_profile_picture_path, html: { multipart: true }, method: :patch) do |f|
|
||||||
|
|
||||||
.media#profile-picture-media
|
.media#profile-picture-media
|
||||||
.pull-left
|
.pull-left
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
= f.primary
|
= f.primary
|
||||||
.card
|
.card
|
||||||
.card-body
|
.card-body
|
||||||
= bootstrap_form_for(current_user.profile, url: { action: :update_profile }, html: { multipart: true }, method: :patch) do |f|
|
= bootstrap_form_for(current_user.profile, html: { multipart: true }, method: :patch) do |f|
|
||||||
|
|
||||||
= f.text_field :display_name
|
= f.text_field :display_name
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,9 @@ Rails.application.routes.draw do
|
||||||
resource :theme, controller: :theme, only: %i[edit update destroy]
|
resource :theme, controller: :theme, only: %i[edit update destroy]
|
||||||
|
|
||||||
get :profile, to: redirect('/settings/profile/edit')
|
get :profile, to: redirect('/settings/profile/edit')
|
||||||
resource :profile, controller: :profile, only: %i[edit update update_profile]
|
resource :profile, controller: :profile, only: %i[edit update]
|
||||||
|
|
||||||
|
resource :profile_picture, controller: :profile_picture, only: %i[update]
|
||||||
end
|
end
|
||||||
resolve('Theme') { [:settings_theme] } # to make link_to/form_for work nicely when passing a `Theme` object to it, see also: https://api.rubyonrails.org/v6.1.5.1/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-resolve
|
resolve('Theme') { [:settings_theme] } # to make link_to/form_for work nicely when passing a `Theme` object to it, see also: https://api.rubyonrails.org/v6.1.5.1/classes/ActionDispatch/Routing/Mapper/CustomUrls.html#method-i-resolve
|
||||||
resolve('Profile') { [:settings_profile] }
|
resolve('Profile') { [:settings_profile] }
|
||||||
|
|
Loading…
Reference in New Issue