https://avo.cool logo
Document scanning resource tool
# avo-3
m
I'd like to create a custom photo uploader. In a nutshell, I'd like to create an "scan a document" functionality using https://github.com/puffinsoft/jscanify. So the user could use the camera to rectify an image. I guess that's a job for a resource tool?
m
Thread automatically created by julianrubisch in #1138182212655788054
l
That or a regular tool if it’s not tied to a specific resource
Or, you could create a custom field
That might be more appropriate
m
Hm yeah probably the latter. Have to look into my options here.
okay, I feel stupid. I've created a custom field from a template:
Copy code
bin/rails g avo:field document_scan --field_template file 
Avo community 3.24.1
      create  app/components/avo/fields/document_scan_field
      create  app/components/avo/fields/document_scan_field/edit_component.html.erb
      create  app/components/avo/fields/document_scan_field/edit_component.rb
      create  app/components/avo/fields/document_scan_field/index_component.html.erb
      create  app/components/avo/fields/document_scan_field/index_component.rb
      create  app/components/avo/fields/document_scan_field/show_component.html.erb
      create  app/components/avo/fields/document_scan_field/show_component.rb
      create  app/avo/fields/document_scan_field.rb
but when I add it to my resource:
Copy code
field :image, as: :document_scan, is_image: true
it complains in the Rails logs that it couldn't find the component.
Copy code
Failed to find component for the `Avo::Fields::DocumentScanField` field on the `show` view.
tried just with
scan
, same issue:
Copy code
[Avo->] 2025-09-18 14:03:14 +0200: Failed to find component for the `Avo::Fields::ScanField` field on the `show` view.
🤯
(I've restarted the app server several times)
@loud-jewelry-99127 can you help me out here? It feels like I‘m missing something really basic
l
Hi @millions-exabyte-27721 Can you debug arround here? https://github.com/avo-hq/avo/blob/428b13ff4504fe9d9fd457b80b5019ade1eabfe0/lib%2Favo%2Ffields%2Fconcerns%2Fuse_view_components.rb#L32 Let me know the value of the variable
component_class
m
ah, I missed the fallback! give me a sec
yeah it's
"Avo::Fields::ScanField::ShowComponent"
that does sound correct though
Copy code
# frozen_string_literal: true

class Avo::Fields::ScanField::ShowComponent < Avo::Fields::ShowComponent
end
that looks like some zeitwerk f**kup, hang on
indeed if I put a breakpoint in the
rescue
block, the raw error message is
"uninitialized constant Avo::Fields::ScanField::ShowComponent"
but why...
I think the path is right:
Copy code
ls -la app/components/avo/fields/scan_field/show_component.rb
-rw-r--r--  1 jrubisch  staff  108 Sep 18 14:02 app/components/avo/fields/scan_field/show_component.rb
ah wait a second... could this be an incompatibility between view_component and phlex maybe? because that's what I'm using in that app
it's here btw, you can try it yourself: https://github.com/julianrubisch/fridge_door
l
I'll try it out when I get a chance
It's wierd
I think it's not about phlex
@millions-exabyte-27721 any idea?
Copy code
ruby
fridge-door(dev)> Artist.create!(first_name: "First", last_name: "Last")
  TRANSACTION (0.1ms)  BEGIN immediate TRANSACTION /*application='FridgeDoor'*/
  Artist Create (1.2ms)  INSERT INTO "artists" ("first_name", "last_name", "date_of_birth", "created_at", "updated_at") VALUES ('First', 'Last', NULL, '2025-09-19 19:34:42.483174', '2025-09-19 19:34:42.483174') RETURNING "id" /*application='FridgeDoor'*/
  TRANSACTION (0.1ms)  ROLLBACK TRANSACTION /*application='FridgeDoor'*/
(fridge-door):1:in '<main>': SQLite3::SQLException: unknown function: ULID(): (ActiveRecord::StatementInvalid)
INSERT INTO "artists" ("first_name", "last_name", "date_of_birth", "created_at", "updated_at") VALUES ('First', 'Last', NULL, '2025-09-19 19:34:42.483174', '2025-09-19 19:34:42.483174') RETURNING "id" /*application='FridgeDoor'*/
/home/bob/.rbenv/versions/3.4.4/lib/ruby/gems/3.4.0/gems/sqlite3-2.7.3-x86_64-linux-gnu/lib/sqlite3/statement.rb:36:in 'SQLite3::Statement#prepare': unknown function: ULID(): (SQLite3::SQLException)
INSERT INTO "artists" ("first_name", "last_name", "date_of_birth", "created_at", "updated_at") VALUES ('First', 'Last', NULL, '2025-09-19 19:34:42.483174', '2025-09-19 19:34:42.483174') RETURNING "id" /*application='FridgeDoor'*/
The problem is here ☝️
you're changing the components default namespace
m
Ah yeah forgot about that 🙈 I‘m using a private template I made for myself. Thanks for looking into it
Let’s see if I get it working
Btw the error you saw is because you need to install an SQLite package. But I thought I included that in bin/setup
l
It's all right, I found the issue using the new view instead show view 😄
m
Might also be worth a mention in the troubleshooting section. 🤔 anyway I’ll report how the custom field evolves, I‘m pretty excited about this
l
All right! Keep us updated! I would merge a contribution for a mention in the troubleshooting section. Would you like to push a PR with the fix for it? (I don't know what the fix is, I only found the issue :D)
m
I’ll do so as soon as I fix it 😂
okay, option 2 from https://www.phlex.fun/introduction/getting-started#conflicts-with-the-viewcomponent-gem worked 🎉 indeed #1 could only work if Avo exposed the "component root module" in a config or something.... but I think documenting #2 is fine!