proud-breakfast-80041
06/14/2024, 3:48 PMproud-breakfast-80041
06/28/2024, 4:18 PMlively-ability-6202
07/11/2024, 3:11 PMmammoth-xylophone-46880
07/24/2024, 10:25 AMlively-ability-6202
07/25/2024, 1:43 PMruby
field :revenue_share_breakdown, as: :text, as_html: true, only_on: :show do
record.bookkeeping_explanation(:owner)
end
ruby
def revenue_share_breakdown(_rows)
erb_template = Rails.root.join('app/views/clients/accounts/transactions/_revenue_share_breakdown.html.erb').read
formatted_html = ERB.new(erb_template).result(binding)
formatted_html.gsub(/\n+/, '')
end
https://cdn.discordapp.com/attachments/1266027985484648489/1266027998990176276/image.png?ex=66a3a7f4&is=66a25674&hm=2c851c17e96c239f0a88f39564ce7111fafd1d29216e6a2a13cac03a0173a750&lively-ability-6202
08/28/2024, 8:43 AMstraight-pager-31449
08/30/2024, 2:05 PMstraight-pager-31449
08/31/2024, 6:01 AMlively-ability-6202
10/14/2024, 1:43 PMstraight-pager-31449
11/22/2024, 2:00 AMstraight-pager-31449
11/24/2024, 5:43 AMstraight-pager-31449
12/05/2024, 3:28 PM2024-11-20 22:41:00 +0000___foobarid
class CompositePrimaryKeyFormatter
def self.format(id)
return id if id.is_a?(Array)
if id.match?(/\+\d{4}/) && id.include?('__') && (match = id.match(/(\+\d{4})/))
timestamp = "#{match.pre_match}+0900"
rest = match.post_match.strip.sub(/^_/, '')
[timestamp, rest]
else
id
end
end
end
This is likely better approached using a different method, but it is documented here as a temporary workaround.cool-minister-27228
12/11/2024, 4:04 PMruby
class Avo::Actions::ExportCsv < Avo::BaseAction
self.name = "Export all data as CSV"
self.standalone = true
self.may_download_file = true
def handle(query:, fields:, current_user:, resource:, **args)
records = resource.class.query_scope
resource.hydrate(view: "index")
resources = records.map do |record|
resource.dup.hydrate(record: record)
end
return error 'No records to export' if resources.empty?
csv = CSV.generate do |csv|
first_resorce = resources.first
first_resorce.detect_fields
header_fields = first_resorce.get_fields(reflection: nil, only_root: true).reject{ |field|field.id == :preview }
csv << header_fields.map(&:name)
resources.each do |resource_row|
resource_row.detect_fields
row_fields = resource_row.get_fields(reflection: nil, only_root: true).reject{ |field|field.id == :preview }
csv << row_fields.map do |field|
if field.value.is_a?(ApplicationRecord)
Avo.resource_manager.get_resource_by_model_class(field.value.class).new(record: field.value).record_title
else
field.value
end
end
end
end
download csv, "#{resource.name.downcase.pluralize}_#{ Time.now.strftime('%Y-%m-%d_%H-%M-%S') }.csv"
end
end
straight-pager-31449
01/10/2025, 1:43 AM- config/initializers/avo.rb
Avo.configure do |config|
Rails.configuration.to_prepare do
Pagy::Backend.prepend(CustomPagyBackend)
module CustomPagyBackend
private
# override the pagy_get_count method adding
# the Rails.cache wrapper around the count call
def pagy_get_count(collection, _vars)
cache_key = "pagy-#{collection.model.name}:#{collection.to_sql}"
Rails.cache.fetch(cache_key, expires_in: 20 * 60) do
collection.count(:all)
end
end
> cache the count
https://ddnexus.github.io/pagy/docs/how-to/#deal-with-a-slow-collection-countmillions-exabyte-27721
01/10/2025, 6:40 AMmillions-exabyte-27721
02/03/2025, 5:44 PMstraight-pager-31449
02/18/2025, 11:31 AMfield :foo, as: :has_many, scope: -> {
query.limit(3) # limit does not work
}
https://discord.com/channels/740892036978442260/1340959611410448415/1341370592196034621straight-pager-31449
02/21/2025, 5:13 PM// Global listener to intercept Enter key events during IME composition.
// This prevents unwanted "apply" actions when confirming input via an IME
document.addEventListener(
"keydown",
(event) => {
// If the key is not "Enter" or IME is not composing, exit early.
if (event.key !== "Enter" || !event.isComposing) return;
event.stopImmediatePropagation();
},
true // Use capture phase to intercept the event as early as possible.
);
lively-ability-6202
02/24/2025, 8:47 AMflaky-room-51691
02/27/2025, 3:36 PMfuture-match-90639
03/03/2025, 6:30 PMskip-avo-resource
, but it would be on an individual scaffold.
I was thinking of /initializers/avo.rb
/ self.skip_scaffolds = true
straight-pager-31449
03/31/2025, 2:41 PMclass Avo::Resources::User < ...
...
def custom_my_scope(name:, description:, query_value:)
klass = Class.new(Avo::Advanced::Scopes::BaseScope) do
self.name = -> { name }
self.description = "this is #{description} scope"
self.scope = -> { query.where(foobar: query_value) }
end
# Create a unique constant name based on the provided name and query_key
const_name = "CustomMyScope_#{name.gsub(/\s+/, '')}_#{query_value}".gsub(/[^A-Za-z0-9_]/, '')
Object.const_set(const_name, klass)
end
def scopes
scope custom_my_scope(name: 'foo1', description: 'foo1 description', query_value: 'user')
scope custom_my_scope(name: 'foo2', description: 'foo2 description', query_value: 'admin')
scope custom_my_scope(name: 'foo3', description: 'foo3 description', query_value: 'blocked')
...
straight-pager-31449
04/10/2025, 8:36 AMstraight-pager-31449
04/15/2025, 2:37 PMlemon-wall-20836
04/24/2025, 7:29 AMfuture-match-90639
06/06/2025, 9:56 AMmasquerade_path(record)
isn't working.
I found a workaround but it looks awful.
What should I do?
PR here: https://github.com/yshmarov/moneygun/pull/275future-match-90639
07/10/2025, 11:40 AMfuture-match-90639
07/15/2025, 2:51 PMfuture-match-90639
07/15/2025, 7:13 PMdef fields
with_options(only_on: [:index, :show, :edit]) do
field :category_ids,
as: :select,
multiple: true,
options: -> { Category.options_for_select },
html: {edit: {wrapper: {style: "margin-bottom: 13rem;"}, input: {data: {controller: "avo-tom_select"}}}}
end
app/javascript/controllers/avo/tom_select_controller.js
import { Controller } from '@hotwired/stimulus'
import TomSelect from 'tom-select'
import 'tom-select/dist/css/tom-select.css'
export default class extends Controller {
connect() {
console.log('tom-select controller connected')
if (!this.element.tomSelect) {
new TomSelect(this.element, {
plugins: ['remove_button'],
create: false,
maxItems: null,
searchField: ['text']
})
}
}
}
app/views/avo/partials/_head.html.erb
<%= stylesheet_link_tag "avo.custom", media: "all", "data-turbo-track": "reload" %>
<%= javascript_include_tag "avo.custom", "data-turbo-track": "reload", defer: true %>
https://cdn.discordapp.com/attachments/1125160641569771550/1394758741966065837/Screenshot_2025-07-15_at_21.10.54.png?ex=6877f9cd&is=6876a84d&hm=6df105c46c1ce3a0d0a2afbc7a216114b693b87ce3e7295687f728e0ee9442b2&lively-ability-6202
07/17/2025, 1:58 AM