A
A
Alexander Petrov2021-02-10 13:24:28
Ruby on Rails
Alexander Petrov, 2021-02-10 13:24:28

How to render svg code in the controller so that it is available through the tag?

I have an svg image code in my controller. How to render so that the image can be used in the tag?

def render_image
    
    html="<code_my_svg_image>"

    respond_to do |format|
      format.svg { 
        render inline: html.to_s, content_type: 'image/svg+xml'
      }
    end

  end


What the controller looks like now. I have route set to this method.

This option works, as I understand it, it gives just an html page, but it needs to be given exactly as a file. What needs to be changed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question