Forum: Ruby on Rails Rendering dynamic Gruff image (send_data)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mathieu C. (Guest)
on 2006-01-09 14:59
(Received via mailing list)
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

<img src="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
Alex Y. (Guest)
on 2006-01-09 15:08
(Received via mailing list)
Mathieu C. wrote:
>
> <img src="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...
Mathieu C. (Guest)
on 2006-01-09 15:24
(Received via mailing list)
> > <img src="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!
Sky Y. (Guest)
on 2006-01-09 15:33
(Received via mailing list)
Just use <img src="/stats/make_graph"/>. Image_tag is too wordy here.
Dylan M. (Guest)
on 2006-01-19 00:53
(Received via mailing list)
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Jarkko L. (Guest)
on 2006-01-19 11:12
(Received via mailing list)
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 <img src=...> 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
Alex Y. (Guest)
on 2006-01-19 11:36
(Received via mailing list)
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 <img src=...> tag to get it to work.
In that case:

<%= tag 'img', :src => url_for(...), :alt => 'foo' %>
This topic is locked and can not be replied to.