I''m trying to create a product list page that will show text data for my product as well as a thumbnail image of my product. All the product data, including the image are stored in the db. I''m having trouble with the code that will display the image from the database. Ultimately I''d like to have this image cached on the file system until it changes. If anyone has done, this or can point me to some sample code that performs this action I would greatly appreciate it. I''ve been able to successfully download the image from the database or send the data using send_data from my controller to the browser, but displaying the image in an <img> tag in the html has caused me problems. I''m sure this is quite simple, but I''ve not figured it out yet. Thanks, Joe _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Is this what you are looking for? <%= image_tag(@image_url) %> If you can extract the image to the file system in a web accessible directory... then you could just pass that in to the image_tag method. Tom On 9/17/05, Joe Goldwasser <joe-Ilt5GlnZSIc@public.gmane.org> wrote:> > > > I''m trying to create a product list page that will show text data for my > product as well as a thumbnail image of my product. All the product data, > including the image are stored in the db. > > > > I''m having trouble with the code that will display the image from the > database. Ultimately I''d like to have this image cached on the file system > until it changes. If anyone has done, this or can point me to some sample > code that performs this action I would greatly appreciate it. > > > > I''ve been able to successfully download the image from the database or send > the data using send_data from my controller to the browser, but displaying > the image in an <img> tag in the html has caused me problems. I''m sure this > is quite simple, but I''ve not figured it out yet. > > > > Thanks, > > Joe > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
On 18.9.2005, at 6.37, Tom Davies wrote:> Is this what you are looking for? > > <%= image_tag(@image_url) %>You can make an action that uses send_data to send the image data. Then use page caching on that action. After that, it''s just a matter of <%= image_tag(url_for action => "thumbnail", id => image.id) %> Optionally, you can create a route for the thumbnail action so its uri will look like a real image file: map.connect ''images/thumbnail/:id/thumbail.jpg'', :controller => ''images'', :action => ''thumbnail'' After that the url_for call above will automatically create url''s like /images/thumbnail/178/thumbnail.jpg and they will be parsed to call the right action. //jarkko> > If you can extract the image to the file system in a web accessible > directory... then you could just pass that in to the image_tag method. > > Tom > > On 9/17/05, Joe Goldwasser <joe-Ilt5GlnZSIc@public.gmane.org> wrote: > >> >> >> >> I''m trying to create a product list page that will show text data >> for my >> product as well as a thumbnail image of my product. All the >> product data, >> including the image are stored in the db. >> >> >> >> I''m having trouble with the code that will display the image from the >> database. Ultimately I''d like to have this image cached on the >> file system >> until it changes. If anyone has done, this or can point me to >> some sample >> code that performs this action I would greatly appreciate it. >> >> >> >> I''ve been able to successfully download the image from the >> database or send >> the data using send_data from my controller to the browser, but >> displaying >> the image in an <img> tag in the html has caused me problems. I''m >> sure this >> is quite simple, but I''ve not figured it out yet. >> >> >> >> Thanks, >> >> Joe >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 9/18/05, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> > On 18.9.2005, at 6.37, Tom Davies wrote: > > > Is this what you are looking for? > > > > <%= image_tag(@image_url) %> > > You can make an action that uses send_data to send the image data. > Then use page caching on that action.I''m doing this. When /images/thumbnail/<id> is called, the image is generated and is cached in public/images/thumbnail/<id>.html. Subsequent calls to /images/thumbnail/<id> result in a regeneration of the image... the <id>.html file is not being used. Any ideas?> After that, it''s just a matter of > > <%= image_tag(url_for action => "thumbnail", id => image.id) %> > > Optionally, you can create a route for the thumbnail action so its > uri will look like a real image file: > map.connect ''images/thumbnail/:id/thumbail.jpg'', :controller => > ''images'', :action => ''thumbnail'' > > After that the url_for call above will automatically create url''s > like /images/thumbnail/178/thumbnail.jpg and they will be parsed to > call the right action. > > //jarkko > > > > > If you can extract the image to the file system in a web accessible > > directory... then you could just pass that in to the image_tag method. > > > > Tom > > > > On 9/17/05, Joe Goldwasser <joe-Ilt5GlnZSIc@public.gmane.org> wrote: > > > >> > >> > >> > >> I''m trying to create a product list page that will show text data > >> for my > >> product as well as a thumbnail image of my product. All the > >> product data, > >> including the image are stored in the db. > >> > >> > >> > >> I''m having trouble with the code that will display the image from the > >> database. Ultimately I''d like to have this image cached on the > >> file system > >> until it changes. If anyone has done, this or can point me to > >> some sample > >> code that performs this action I would greatly appreciate it. > >> > >> > >> > >> I''ve been able to successfully download the image from the > >> database or send > >> the data using send_data from my controller to the browser, but > >> displaying > >> the image in an <img> tag in the html has caused me problems. I''m > >> sure this > >> is quite simple, but I''ve not figured it out yet. > >> > >> > >> > >> Thanks, > >> > >> Joe > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > >> > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >