You need a separate action for the image. product.faux_thumbnail would
create a link to /controller/image/1234
Then you have an action called "image" that generates the image and
sends it
with send_data.
Don''t know if that''s what you''re asking, seems pretty
straightforward to do.
Here''s an example of a game I made:
def board
board = Image.new( 306, 306, HatchFill.new( ''white'',
''black'', 51 ) )
board.border!( 1, 1, ''black'' )
send_data(board.to_blob { self.format = ''GIF'' },
:filename => ''board.gif'',
:type => ''image/gif'',
:disposition => ''inline'')
end
<img src="<%= url_for :controller => ''game'',
:action => ''board'' %>" id="b"/>
-Jeff
----- Original Message -----
From: "Steve Ross"
<sross-ju+vs0qJmycyYsO2DCxJlVaTQe2KTcn/@public.gmane.org>
To: <rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org>
Sent: Friday, July 01, 2005 2:55 PM
Subject: [Rails] Dynamic Image Display
>I have what seems a common task:
>
> 1. In response to a user request, look for a thumbnail of a product.
> 2. If no thumbnail, generate one using RMagick and store in database.
> 3. In either case render bits to browser, either from blob in database or
> computed thumbnail
>
> This problem seems to straddle the model and controller patterns. It
> occurred to me that a helper could handle it, but I would prefer not to
> use
> one, as an attribute seems so much cleaner. What I would like is:
>
> <img src="<%= product.faux_thumbnail %>" />
>
> And all the magic in steps 1..3 happen.
>
> Any suggestion where in the application structure to place this logic
> (send_data only seems to work in controllers...).
>
> Thanks
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails