DEV: Minor refactor for bookmark polymorphic changes (#20733)
Followup to 184ce647ea
,
this just implements Bianca's suggestion on the original
PR and catches the NameError, which was not necessary
before as we were not actually resolving any class from
bookmarkable_type.
This commit is contained in:
parent
25d06faa8b
commit
2f6987a241
|
@ -11,7 +11,14 @@ class Bookmark < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.registered_bookmarkable_from_type(type)
|
||||
Bookmark.registered_bookmarkables.find { |bm| bm.model.name == type }
|
||||
begin
|
||||
resolved_type = Bookmark.polymorphic_class_for(type).name
|
||||
Bookmark.registered_bookmarkables.find { |bm| bm.model.name == resolved_type }
|
||||
|
||||
# If the class cannot be found from the provided type using polymorphic_class_for,
|
||||
# then the type is not valid and thus there will not be any registered bookmarkable.
|
||||
rescue NameError
|
||||
end
|
||||
end
|
||||
|
||||
def self.valid_bookmarkable_types
|
||||
|
@ -46,8 +53,7 @@ class Bookmark < ActiveRecord::Base
|
|||
validates :name, length: { maximum: 100 }
|
||||
|
||||
def registered_bookmarkable
|
||||
type = Bookmark.polymorphic_class_for(self.bookmarkable_type).name
|
||||
Bookmark.registered_bookmarkable_from_type(type)
|
||||
Bookmark.registered_bookmarkable_from_type(self.bookmarkable_type)
|
||||
end
|
||||
|
||||
def polymorphic_columns_present
|
||||
|
|
Loading…
Reference in New Issue