# How to integrate Scruff Images

**URL:** <https://www.ruby-forum.com/t/how-to-integrate-scruff-images/75498>\
**Category:** Rails\
**Created:** [November 10, 2006, 12:12pm UTC](https://www.ruby-forum.com/t/how-to-integrate-scruff-images/75498 "2006-11-10T12:12:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 10, 2006, 12:12pm UTC](https://www.ruby-forum.com/t/how-to-integrate-scruff-images/75498/1 "2006-11-10T12:12:44Z")

</div>

Hi Folks,

since I have scruffy up and running now IÂ´d like to integrate the  
desired images on some of my rails views. But neither scruffy nor rails  
docs say something about this and I cannot find examples or help on  
this. So I hope somebody on this forum has experiences in integrating  
scruffy images on rails views.

I find out how to go the easy and obvious way: Export image to a file  
and then bind the exported file on the view template. But I wonder if I  
cannot get scruffy images directly on my rails pages without exporting  
it to disk first.

My approach with a simple example from Brastens page:  
I created this method in my views helper class:  
def generate\_img()  
graph = Scruffy::Graph.new

```
graph.title = "Comparative Agent Performance"
graph.value_formatter = 

```

Scruffy::Formatters::Percentage.new(:precision =\> 0)

```
graph.add :stacked do |stacked|
  stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
  stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
  stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
end

graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']

graph.render(:width => 800, :as => 'JPG')

```

end

And in my views rhtml page I put this:  
\<%= generate\_img %\>

Unfortunately it display rubbish instead of the expected image.

The encapsulation with the ![]() tag is also not working.

Can anyone point me to the right direction?

Thanks & Regards,

Christian

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 10, 2006, 12:14pm UTC](https://www.ruby-forum.com/t/how-to-integrate-scruff-images/75498/2 "2006-11-10T12:14:29Z")

</div>

Doh! Mixed up the name in the headline: Must be “Scruffy” not “Scruff”.  
Sorry!

---

<div class="post-metadata">

**Author:** ![caefer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e36b37/32.png) [@caefer](https://www.ruby-forum.com/u/caefer)\
**Post date:** [November 10, 2006, 1:52pm UTC](https://www.ruby-forum.com/t/how-to-integrate-scruff-images/75498/3 "2006-11-10T13:52:47Z")

</div>

Okay I figured it out myself, should have had a closer look on this  
forum before 😉

Here we go:  
In my controller I added this method:  
def show\_img  
graph = Scruffy::Graph.new

```
graph.title = "Comparative Agent Performance"
graph.value_formatter = 

```

Scruffy::Formatters::Percentage.new(:precision =\> 0)

```
graph.add :stacked do |stacked|
  stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
  stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
  stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
end

graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']

send_data(graph.render(:width => 800, :as => 'PNG'), :type => 

```

‘image/png’, :disposition=\> ‘inline’)  
end

And in the views rhtml file I added this:  
 ![]()

And now it works!

Regards,

Chris
