render association as svg
# avo-2
n
Hi everyone, I have an Icon resource where I can add an SVG code and a name. I also have an Answer which might have an Icon associated with it. On the models I have
Answer belongs_to :icon
and
Icon has_many :answers
In the Answer resource I've added
field :icon, as: :belongs_to
. Do you know if it's possible to show the rendered SVG in the select field that's generated instead of the name?
l
That's not possible with that configuration. What you could is add a new field that will render that svg on
show
and hide the other one
Copy code
ruby
  field :icon, as: :belongs_to, hide_on: :show
  field :rendered_icon,
    as: :text,
    as_html: true, # enables it to be rendered as HTML
    only_on: :show, # show it only on the show view
    format_using: -> {
      model.icon.content # get the content from teh associated `icon`
    }