We were seeing an exception when a user was following a proposal and
that proposal becomes hidden
With this commit we are skipping this proposals and hopefully fixing
this exception
We are also adjusting the count of followed proposals, without
including hidden proposals. It might be cleaner, to remove a `Follow`
when its `Followable` becomes hidden. But then we should probably
activate the `Follow` again if the `Followable` becomes non-hidden…
For now this commit should suffice 😌
33 lines
769 B
Ruby
33 lines
769 B
Ruby
module FollowablesHelper
|
|
|
|
def followable_type_title(followable_type)
|
|
t("activerecord.models.#{followable_type.underscore}.other")
|
|
end
|
|
|
|
def followable_icon(followable)
|
|
{
|
|
proposals: 'Proposal',
|
|
budget: 'Budget::Investment'
|
|
}.invert[followable]
|
|
end
|
|
|
|
def render_follow(follow)
|
|
return unless follow.followable.present?
|
|
|
|
followable = follow.followable
|
|
partial = followable_class_name(followable) + "_follow"
|
|
locals = {followable_class_name(followable).to_sym => followable}
|
|
|
|
render partial, locals
|
|
end
|
|
|
|
def followable_class_name(followable)
|
|
followable.class.to_s.parameterize('_')
|
|
end
|
|
|
|
def find_or_build_follow(user, followable)
|
|
Follow.find_or_initialize_by(user: user, followable: followable)
|
|
end
|
|
|
|
end
|