# Rendering dynamic Gruff image (send\_data)

**URL:** <https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937>\
**Category:** Rails\
**Created:** [January 9, 2006, 1:59pm UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937 "2006-01-09T13:59:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mathieu\_C](https://www.ruby-forum.com/u/Mathieu_C)\
**Post date:** [January 9, 2006, 1:59pm UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937/1 "2006-01-09T13:59:47Z")

</div>

Dears,

Got a controller witch do a send\_data for displaying a chart.

like :

send\_data(g.to\_blob, :filename =\> “any.png”, :type =\> ‘image/png’,  
:disposition=\> ‘inline’)

I actually do a

![](http://myhost:3000/stats/make_graph)

Is there any way more clean to do that ? At minima don’t hardcode the  
beginning of the url (host:port)

I’ve tried a bit ‘render’ w/o success.

Thanks

---

<div class="post-metadata">

**Author:** ![Mathieu\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mathieu\_C](https://www.ruby-forum.com/u/Mathieu_C)\
**Post date:** [January 9, 2006, 2:08pm UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937/2 "2006-01-09T14:08:52Z")

</div>

Mathieu C. wrote:

> ![](http://myhost:3000/stats/make_graph)
> 
> Is there any way more clean to do that ? At minima don’t hardcode the  
> beginning of the url (host:port)  
> \<%= image\_tag(url\_for(:action =\> ‘make\_graph’, :controller =\> ‘stats’))  
> %\>

Should do it…

---

<div class="post-metadata">

**Author:** ![Mathieu\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mathieu\_C](https://www.ruby-forum.com/u/Mathieu_C)\
**Post date:** [January 9, 2006, 2:24pm UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937/3 "2006-01-09T14:24:10Z")

</div>

> > ![](http://myhost:3000/stats/make_graph)
> > 
> > Is there any way more clean to do that ? At minima don’t hardcode the  
> > beginning of the url (host:port)  
> > \<%= image\_tag(url\_for(:action =\> ‘make\_graph’, :controller =\> ‘stats’)) %\>
> 
> Should do it…

Thanks very much!

---

<div class="post-metadata">

**Author:** ![Mathieu\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mathieu\_C](https://www.ruby-forum.com/u/Mathieu_C)\
**Post date:** [January 18, 2006, 11:53pm UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937/4 "2006-01-18T23:53:35Z")

</div>

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![Mathieu\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mathieu\_C](https://www.ruby-forum.com/u/Mathieu_C)\
**Post date:** [January 9, 2006, 2:33pm UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937/5 "2006-01-09T14:33:27Z")

</div>

Just use ![](https://www.ruby-forum.com/stats/make_graph). Image\_tag is too wordy here.

---

<div class="post-metadata">

**Author:** ![Mathieu\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mathieu\_C](https://www.ruby-forum.com/u/Mathieu_C)\
**Post date:** [January 19, 2006, 10:12am UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937/6 "2006-01-19T10:12:03Z")

</div>

On 19.1.2006, at 0.16, Dylan M. wrote:

> When I try something like this, the resulting HTML links to “/stats/  
> make\_graph.png” instead of “/stats/make\_graph”. Because of this,  
> only the “alt” title shows up with no graph. I have to manually  
> create an ![]() tag to get it to work.

image\_tag is a bit “too” wise in this case, because it adds the .png  
to the image name by default if there’s no suffix.

You can fix it by creating a route like this:  
map.connect ‘stats/make\_graph.png’, :controller =\> ‘stats’, :action  
=\> ‘make\_graph’

and putting it in your config/routes.rb. Then the image url even  
looks like an image filename.

//jarkko

---

<div class="post-metadata">

**Author:** ![Mathieu\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mathieu\_C](https://www.ruby-forum.com/u/Mathieu_C)\
**Post date:** [January 19, 2006, 10:36am UTC](https://www.ruby-forum.com/t/rendering-dynamic-gruff-image-send-data/51937/7 "2006-01-19T10:36:25Z")

</div>

Dylan M. wrote:

> When I try something like this, the resulting HTML links to  
> “/stats/make\_graph.png” instead of “/stats/make\_graph”. Because of this,  
> only the “alt” title shows up with no graph. I have to manually create  
> an ![]() tag to get it to work.  
> In that case:

\<%= tag ‘img’, :src =\> url\_for(…), :alt =\> ‘foo’ %\>
