Dynamic image creation using gruff in ruby on rails

741 Views Asked by At

I am new to Ruby on Rails and working on Graph creation using 'Gruff'. In controller I am writing below code to create image in assets/images.

g.write("#{Rails.root}/app/assets/images/chart/chart.png")   

and in view : <%= image_tag("chart/chart.png", :alt => "Image missing") %>

By using this way I can perfectly see image in the view, but storing images in assets/images will consume a lot of memory.

Is there an alternative to create image dynamically without storing it in assets/images?

1

There are 1 best solutions below

0
On

In the controller instead of writing the image, use:

 send_data(g.to_blob, :disposition => 'inline',  :type => 'image/png',  :filename => "chart.png

It will not create image but display it on view.