1

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?

achedeuzot
  • 4,164
  • 4
  • 41
  • 56

1 Answers1

0

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.

Ritesh Kumar
  • 2,183
  • 2
  • 20
  • 32