straight-pager-31449
08/04/2023, 1:21 PM---
field :title,
as: :text, hide_on: %i[show edit new],
format_using: -> {
content_tag(:div, class: 'whitespace-pre-line', style: 'width: 200px; word-wrap: break-word;') do
truncate40(value) # it doesn't work. (undefined method `truncate40'). It worked with Avo 2.29.1.
end
}
---
module FieldHelper
def truncate40(value)
return if value.blank?
ActionView::Base.full_sanitizer.sanitize(value).truncate 40
end
end
loud-jewelry-99127
08/04/2023, 1:46 PMAvo::ExecutionContext
to ensure proper isolation of the context in which the Procs are executed. Since the format_using
lambda runs in isolation, it only has access to what we pass inside the Avo::ExecutionContext
.
I noticed that the includes are not being passed currently. To address this, I'll create a pull request (PR) that will fix it. In the meantime, you can use the following temporary fix:
ruby
field :title,
as: :text, hide_on: %i[show edit new],
format_using: -> {
content_tag(:div, class: 'whitespace-pre-line', style: 'width: 200px; word-wrap: break-word;') do
extend field.class.included_modules.find { |m| m.name == "FieldHelper" }
truncate40(value)
end
}
Notice that is only a temporary fix, I'll keep you updated on the PR progress in this thread.
Let me know if it works.straight-pager-31449
08/04/2023, 1:52 PMloud-jewelry-99127
08/04/2023, 2:03 PMstraight-pager-31449
08/04/2023, 2:40 PM