lemon-wall-20836
02/14/2025, 9:14 AMloud-jewelry-99127
02/14/2025, 10:25 AMloud-jewelry-99127
02/14/2025, 10:25 AMmillions-exabyte-27721
02/20/2025, 9:55 AMhas_many
associations pointing to an STI model (I've read https://docs.avohq.io/3.0/associations.html):
I understand that using link_to_child_resource
I can opt into linking to a child resource from the association's table in the parent resource.
However, is there a built-in/simple way to choose which child resource to create?millions-exabyte-27721
02/20/2025, 9:56 AMfield :type, as: :select, ...
?loud-jewelry-99127
02/20/2025, 9:58 AMpolymophic_as
and types
options which will automatically generate a :type field
https://docs.avohq.io/3.0/associations/belongs_to.html#polymorphic_asmillions-exabyte-27721
02/20/2025, 10:04 AMSurvey
) can have specific different children (FreeformSurveyQuestion
, MultipleChoiceSurveyQuestion
, ...)loud-jewelry-99127
02/20/2025, 10:05 AMFreeformSurveyQuestion
, MultipleChoiceSurveyQuestion
, ... are all represented by 1 resource?millions-exabyte-27721
02/20/2025, 10:05 AMmillions-exabyte-27721
02/20/2025, 10:05 AMSurveyQuestion
)millions-exabyte-27721
03/03/2025, 12:30 PMrb
class Surveys::Response < ApplicationRecord
belongs_to :user
belongs_to :surveys_question, class_name: "Surveys::Question"
has_and_belongs_to_many :surveys_question_options,
inverse_of: :surveys_response,
class_name: "Surveys::QuestionOption",
foreign_key: :surveys_response_id,
association_foreign_key: :surveys_question_option_id
end
rb
class Avo::Resources::SurveysSingleChoiceResponse < Avo::BaseResource
# self.includes = []
# self.attachments = []
self.model_class = ::Surveys::SingleChoiceResponse
# self.search = {
# query: -> { query.ransack(id_eq: params[:q], m: "or").result(distinct: false) }
# }
def fields
field :id, as: :id
field :user, as: :belongs_to, readonly: true
field :surveys_question, as: :belongs_to, readonly: true
field :surveys_question_options, as: :has_and_belongs_to_many, readonly: true
end
end
loud-jewelry-99127
03/12/2025, 4:15 PMmillions-exabyte-27721
03/14/2025, 8:12 AMhas_many ... through:
dialog: How can I avoid duplicates showing up in the select box?
I have users I want to attach to segments, but of course it doesn't make sense to attach the same user to a segment twice
I handle this on the database level using a unique index, but of course it'd be nice if those already connected users wouldn't show up in the select box at all...millions-exabyte-27721
03/14/2025, 8:12 AMattach_scope
probably?loud-jewelry-99127
03/25/2025, 9:56 AMclever-iron-16361
03/25/2025, 9:57 AMloud-jewelry-99127
03/25/2025, 9:57 AMmillions-exabyte-27721
03/26/2025, 8:18 AMattach_fields
(https://docs.avohq.io/3.0/associations/has_many.html#attach_fields) to display extra fields when attaching a record of a has_many through:
. In my case it's a simple checkbox
https://cdn.discordapp.com/attachments/740892037640880180/1354368997935546438/image.png?ex=67e509ec&is=67e3b86c&hm=32d6631e8e0cc10af8233c7af865afc4ed22aa2cb2f17f4c9b0eac398785e8b8&lemon-wall-20836
03/28/2025, 2:38 AMlemon-wall-20836
03/28/2025, 2:38 AMmillions-exabyte-27721
03/31/2025, 9:13 AMearly-leather-2501
03/31/2025, 10:25 AM12:09:19 web.1 | 2025-03-31 12:09:19 INFO Rendered layout /Users/michael/.rbenv/versions/3.4.2/lib/ruby/gems/3.4.0/gems/avo-3.18.2/app/views/layouts/avo/application.html.erb (Duration: 153.3ms | GC: 0.0ms)
12:09:19 web.1 | 2025-03-31 12:09:19 INFO Completed 500 Internal Server Error in 649ms (ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)
12:09:19 web.1 |
12:09:19 web.1 |
12:09:19 web.1 | 2025-03-31 12:09:19 ERROR
12:09:19 web.1 | ActionView::Template::Error (undefined method 'avo_dashboards' for an instance of #<Class:0x000000013ca379f0>)
12:09:19 web.1 | Caused by: NoMethodError (undefined method 'avo_dashboards' for an instance of #<Class:0x000000013ca379f0>)
12:09:19 web.1 |
12:09:19 web.1 | Information for: ActionView::Template::Error (undefined method 'avo_dashboards' for an instance of #<Class:0x000000013ca379f0>):
12:09:19 web.1 | 32: <%= render partial: "avo/partials/navbar", locals: { resource: @resource } %>
12:09:19 web.1 | 33: <div data-sidebar-target="mainArea" class="content-area flex-1 flex pt-16 relative <%= "sidebar-open" if @sidebar_open %>">
12:09:19 web.1 | 34: <div class="hidden lg:flex">
12:09:19 web.1 | 35: <%= render Avo::SidebarComponent.new sidebar_open: @sidebar_open %>
12:09:19 web.1 | 36: </div>
12:09:19 web.1 | 37: <div class="flex lg:hidden">
12:09:19 web.1 | 38: <%= render Avo::SidebarComponent.new sidebar_open: false, for_mobile: true %>
12:09:19 web.1 |
12:09:19 web.1 | railties (8.0.2) lib/rails/engine/lazy_route_set.rb:99:in 'method_missing'
12:09:19 web.1 | avo-menu (3.18.2) app/components/avo/sidebar/item_switcher_component.html.erb:8:in 'Avo::Sidebar::ItemSwitcherComponent#call'
12:09:19 web.1 | view_component (3.21.0) lib/view_component/compiler.rb:98
loud-jewelry-99127
04/02/2025, 6:56 AMdry-rainbow-18454
04/02/2025, 1:07 PMcolossal-ambulance-71638
04/02/2025, 7:23 PMrhino
but it's not even close to what TinyMCE gives out of the box.millions-exabyte-27721
04/07/2025, 9:47 AMrecipients
in a list:
rb
class Mailing < ApplicationRecord
belongs_to :mailable, polymorphic: true
delegate :recipients, to: :mailable
end
and an example of a `mailable`:
rb
class Event < ApplicationRecord
has_many :recipients
has_many :mailings, as: :mailable
end
The delegate
is necessary, because you can't specify a has_many through:
on a polymorphic association:
rb
has_many :recipients, through: :mailable
# => Cannot have a has_many :through association 'Mailing#recipients' which goes through the polymorphic association 'Mailing#mailable'. (ActiveRecord::HasManyThroughAssociationPolymorphicThroughError)
I tried to solve this with an Array
field, but failed because it needs an ArrayResource
to back it.
Is there any other way to achieve this?flat-television-5571
04/07/2025, 10:56 AMnested
feature and was getting `undefined method `klass for nil from this method def model
@model ||= @parent_model_class.reflections[@field.name.downcase].klass
end, from avo-advanced (3.19.1) app/components/avo/advanced/nested/field_component.rb:29
, I noticed that I was getting "purchase order items"
from "@field.name.downcase" instead of purchase_order_items. I think this only works if we have model name without underscore.narrow-electrician-89982
04/14/2025, 6:41 AMmillions-exabyte-27721
04/22/2025, 2:45 PMboolean_group
field type, specifically computed options:
I found that if I try to update a record from computed options derived from the record
it does not work. I chased that down to the fact that when I add a breakpoint in the field's computed options lambda and issue a PUT, there, record
is nil:
rb
field :event_roles,
as: :boolean_group,
options: -> do
binding.irb
record&.event&.roles || {}
end
=>
irb(#<Avo::ExecutionContext:0x000...):007> record
=> nil
note that this is not the case when it's called regularly from the edit
view. it also works as expected with options supplied as a regular hashlemon-wall-20836
05/07/2025, 4:24 PM