Hi everyone, I'm working on an action on a model t...
# avo-2
n
Hi everyone, I'm working on an action on a model that uses the prefixed_id gems. The model looks like that:
Copy code
class Quiz < ApplicationRecord
  has_prefix_id :q, minimum_length: 6

  belongs_to :blog
  belongs_to :operation
  has_many :questions
  has_many :answers, through: :questions
  has_and_belongs_to_many :email_accounts
  has_one_attached :rules
.....

end
The action is not yet implemented and I'm just using to learn how it works before I can create a real one:
Copy code
class CopyQuiz < Avo::BaseAction
  self.name = "Make a copy"

  def handle(**args)
    models, fields, current_user, resource = args.values_at(:models, :fields, :current_user, :resource)

    binding.pry
  end
end
When I run the action, I get the following error that's shown in the screenshot. If I remove the has_prefixed_ids it works fine. Does any of you know if this is a problem on the avo side or on the prefixed_ids gem?
l
Hey @nice-ambulance-76519, I investigated this issue and it's Avo issue. Avo it's ignoring the id changing gems while query the records for the actions Until it's officialy fixed you can add this to your resource:
Copy code
ruby
  self.find_record_method = ->(model_class:, id:, params:) do
    if id.is_a?(Array)
      model_class.where(id: id)
    else
      model_class.find(id)
    end
  end
n
Hey @loud-jewelry-99127, thank you so much for your help. It works like a charm. šŸ™
2 Views