Conversation
app/services/member_updater.rb
Outdated
hash = @params.try(:to_unsafe_hash) || @params.to_h # for ActionController::Params | ||
hash.symbolize_keys.compact.keep_if { |k| permitted_keys.include? k } | ||
def member_attributes | ||
@member_attributes ||= Member.new.attributes.keys.map(&:to_sym).select { |k| k != :id } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call column_names
on the class:
Member.column_names.map(&:to_sym)[1..-1]
app/validators/action_kit_fields.rb
Outdated
@@ -67,6 +67,10 @@ class ActionKitFields < ActiveModel::Validator | |||
action_ | |||
).freeze | |||
|
|||
def initialize(name) | |||
@name = name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're worried name
isn't a string, then perhaps call to_s
on it here, rather than below? https://github.com/SumOfUs/Champaign/pull/853/files#diff-e52e089e43530d3d8f597e45e9128cfcR106
app/validators/action_kit_fields.rb
Outdated
end | ||
|
||
def has_valid_prefix | ||
@name =~ VALID_PREFIX_RE | ||
(@name =~ VALID_PREFIX_RE).present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is present?
necessary? nil
is falsy after all. If a boolean is a must then !(@name !~ VALID_PREFIX_RE)
is more expressive, in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm taking your other suggestions, but not this one - !(@name !~ VALID_PREFIX_RE)
is super arcane to me, as I've never seen !~
before and it never occurs in our codebase, whereas =~
is very common. I also think that methods beginning in is_
or has_
should return booleans.
A very fine PR 💯. Merge with extreme prejudice, but not before responding to my comments! |
Your suggested data migration above would bring the site to its knees. Think about using |
@edubsky has been working with phone numbers and turned up two important bugs that I worked on today -
phone
would never have that field prefilled. Rather than just add another column to the table, I added a catchall jsonb column that stores any AK-valid field so this never happens again.These are both fixed. After we deploy, I'm inclined to run something like this to bring the current member records up to speed -