From 27f9d3bda9ac4de22490a798ba59ef0fcd641a67 Mon Sep 17 00:00:00 2001 From: Luis Castro Date: Tue, 6 Aug 2019 16:07:46 +0200 Subject: [PATCH] feat(profiles): add strong params --- app/controllers/profiles_controller.rb | 8 +++++- app/models/profile.rb | 34 ++++++++++++-------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index a471a858..0fcfacfb 100755 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -47,7 +47,7 @@ class ProfilesController < ApplicationController else current_user.profile end - @profile.update_attributes(params[:profile]) + @profile.update_attributes(profile_params) json_saved @profile, 'Profile updated' end @@ -69,4 +69,10 @@ class ProfilesController < ApplicationController redirect_to root_url end end + + private + + def profile_params + params.require(:profile).permit(:registered, :mini_bio, :first_name, :last_name, :name, :phone, :address, :email, :city, :state_code, :zip_code, :privacy_settings, :picture, :anonymous, :city_state, :user_id) + end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 3dba93d8..87377ab2 100755 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -2,24 +2,22 @@ # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later class Profile < ApplicationRecord - # TODO - # attr_accessible \ - # :registered, # bool - # :mini_bio, - # :first_name, # str - # :last_name, # str - # :name, - # :phone, # str - # :address, # str - # :email, # str - # :city, # str - # :state_code, # str (eg. CA) - # :zip_code, # str - # :privacy_settings, # text [str]: XXX deprecated - # :picture, # str: either their social network pic or a stored pic on S3 - # :anonymous, # bool: negates all privacy_settings - # :city_state, - # :user_id + # :registered, # bool + # :mini_bio, + # :first_name, # str + # :last_name, # str + # :name, + # :phone, # str + # :address, # str + # :email, # str + # :city, # str + # :state_code, # str (eg. CA) + # :zip_code, # str + # :privacy_settings, # text [str]: XXX deprecated + # :picture, # str: either their social network pic or a stored pic on S3 + # :anonymous, # bool: negates all privacy_settings + # :city_state, + # :user_id validates :email, format: { with: Email::Regex }, allow_blank: true