Hi all. I am wrting a small content management tool for my company and was trying to display some images from our file store shown below. <td> <img src="\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"/> The app was displaying the image when it is under the \public\images directory. Is there anything special we need to do to get a file from outside the root of the application? Any help appreciated. Thanks Silvy Mathews
send_file ''/path/to.jpeg'', :type => ''image/jpeg'', :disposition => ''inline'' Silvy@funmail.com wrote:> Hi all. > I am wrting a small content management tool for my company and was > trying to display some images from our file store shown below. > <td> <img src="\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"/> > The app was displaying the image when it is under the \public\images > directory. > Is there anything special we need to do to get a file from outside the > root of the application? > > Any help appreciated. > > Thanks > Silvy Mathews > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi John, Thanks for the quick response. I wanted to show the image along with other data from the controller. How do I do that. Looks like I am not understanding it. <td><%= column1 from the model%> <td><%= column1 from the model%> <td><%= column1 from the model%> <td><%= send_file ''\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"'', :type => ''image/jpeg'', :disposition => ''inline''%> Would not work. Sorry for my ignorance. Thanks Silvy Mathews -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of John Bresnik Sent: Wednesday, April 12, 2006 11:53 AM To: rails@lists.rubyonrails.org Subject: Re: [Rails] Showing Images from a file store send_file ''/path/to.jpeg'', :type => ''image/jpeg'', :disposition => ''inline'' Silvy@funmail.com wrote:> Hi all. > I am wrting a small content management tool for my company and was > trying to display some images from our file store shown below. > <td> <img src="\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"/> > The app was displaying the image when it is under the \public\images > directory. > Is there anything special we need to do to get a file from outside the> root of the application? > > Any help appreciated. > > Thanks > Silvy Mathews > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 4/12/06, Silvy@funmail.com <Silvy@funmail.com> wrote:> I wanted to show the image along with other data from the controller. > How do I do that. Looks like I am not understanding it. > ... > <td><%= send_file ''\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"'', > :type => ''image/jpeg'', > :disposition => ''inline''%> >Silvy, What you want to do is set up a controller that handles the dispatching of the images. It is there that you would have the send_file command. Remember that in HTTP you are going to have seperate request for each item on the page, so map the new controller url using routes and use that url in your view, for example "/dynamicimages/abc.gif". Does that make sense? Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060412/dc75ef14/attachment-0001.html
Hi Josh, Thanks for the clarification. Is there any online example somewhere that you are aware of so that I can see it in action? Thanks, Silvy Mathews ________________________________ From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Josh Knowles Sent: Wednesday, April 12, 2006 12:39 PM To: rails@lists.rubyonrails.org Subject: Re: [Rails] Showing Images from a file store On 4/12/06, Silvy@funmail.com <Silvy@funmail.com> wrote: I wanted to show the image along with other data from the controller. How do I do that. Looks like I am not understanding it. ... <td><%= send_file ''\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"'', :type => ''image/jpeg'', :disposition => ''inline''%> Silvy, What you want to do is set up a controller that handles the dispatching of the images. It is there that you would have the send_file command. Remember that in HTTP you are going to have seperate request for each item on the page, so map the new controller url using routes and use that url in your view, for example "/dynamicimages/abc.gif". Does that make sense? Josh -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060412/b4a694db/attachment.html
Yea sorry my response was a little short - that function would go in the controller, i.e. class FileGrabberController < ApplicationController def grab_file send_file ''/path'', :type => ''image/jpeg'', [etc] end end then either call the controller directly using an image tag or use a helper.. let me know if that helps - I can post a working example when I get home tonight [on the laptop at home].. Quoting Silvy@funmail.com:> Hi John, > Thanks for the quick response. > I wanted to show the image along with other data from the controller. > How do I do that. Looks like I am not understanding it. > <td><%= column1 from the model%> > <td><%= column1 from the model%> > <td><%= column1 from the model%> > <td><%= send_file ''\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"'', > :type => ''image/jpeg'', > :disposition => ''inline''%> > > Would not work. Sorry for my ignorance. > > Thanks > Silvy Mathews > > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of John Bresnik > Sent: Wednesday, April 12, 2006 11:53 AM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] Showing Images from a file store > > > send_file ''/path/to.jpeg'', :type => ''image/jpeg'', :disposition => > ''inline'' > > Silvy@funmail.com wrote: > > Hi all. > > I am wrting a small content management tool for my company and was > > trying to display some images from our file store shown below. > > <td> <img src="\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"/> > > The app was displaying the image when it is under the \public\images > > directory. > > Is there anything special we need to do to get a file from outside the > > > root of the application? > > > > Any help appreciated. > > > > Thanks > > Silvy Mathews > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi, Thanks a lot for the response. If you can post a working example, that would be great. Really appreciate it. Thanks Silvy Mathews -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of endaxbrez@endax.com Sent: Wednesday, April 12, 2006 5:15 PM To: rails@lists.rubyonrails.org Subject: RE: [Rails] Showing Images from a file store Yea sorry my response was a little short - that function would go in the controller, i.e. class FileGrabberController < ApplicationController def grab_file send_file ''/path'', :type => ''image/jpeg'', [etc] end end then either call the controller directly using an image tag or use a helper.. let me know if that helps - I can post a working example when I get home tonight [on the laptop at home].. Quoting Silvy@funmail.com:> Hi John, > Thanks for the quick response. > I wanted to show the image along with other data from the controller. > How do I do that. Looks like I am not understanding it. > <td><%= column1 from the model%> > <td><%= column1 from the model%> > <td><%= column1 from the model%> > <td><%= send_file ''\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"'', > :type => ''image/jpeg'', > :disposition => ''inline''%> > > Would not work. Sorry for my ignorance. > > Thanks > Silvy Mathews > > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of John Bresnik > Sent: Wednesday, April 12, 2006 11:53 AM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] Showing Images from a file store > > > send_file ''/path/to.jpeg'', :type => ''image/jpeg'', :disposition => > ''inline'' > > Silvy@funmail.com wrote: > > Hi all. > > I am wrting a small content management tool for my company and was > > trying to display some images from our file store shown below. > > <td> <img src="\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"/> > > The app was displaying the image when it is under the \public\images> > directory. > > Is there anything special we need to do to get a file from outside > > the > > > root of the application? > > > > Any help appreciated. > > > > Thanks > > Silvy Mathews > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Here''s a [very] rough, but working example for a PDF.. Controller: class FileGrabberController < ApplicationController @@path = ''your/path'' def get_file send_file @@path + ''a.pdf'', :type => ''application/pdf'' end end View: <a href="file_grabber/get_file">pdf</a> I know there''s an inline option as well, i.e. for a JPG :disposition => ''inline'' <img src="file_grabber/get_image"/> or something like that - hope that helps.. brez Silvy@funmail.com wrote:> Hi, > Thanks a lot for the response. If you can post a working example, that > would be great. > Really appreciate it. > Thanks > Silvy Mathews > > -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of > endaxbrez@endax.com > Sent: Wednesday, April 12, 2006 5:15 PM > To: rails@lists.rubyonrails.org > Subject: RE: [Rails] Showing Images from a file store > > Yea sorry my response was a little short - that function would go in the > controller, i.e. > > class FileGrabberController < ApplicationController > def grab_file > send_file ''/path'', :type => ''image/jpeg'', [etc] > end > end > > then either call the controller directly using an image tag or use a > helper.. > let me know if that helps - I can post a working example when I get home > tonight [on the laptop at home].. > > > > > > Quoting Silvy@funmail.com: > >> Hi John, >> Thanks for the quick response. >> I wanted to show the image along with other data from the controller. >> How do I do that. Looks like I am not understanding it. >> <td><%= column1 from the model%> >> <td><%= column1 from the model%> >> <td><%= column1 from the model%> >> <td><%= send_file ''\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"'', >> :type => ''image/jpeg'', >> :disposition => ''inline''%> >> >> Would not work. Sorry for my ignorance. >> >> Thanks >> Silvy Mathews >> >> >> -----Original Message----- >> From: rails-bounces@lists.rubyonrails.org >> [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of John Bresnik >> Sent: Wednesday, April 12, 2006 11:53 AM >> To: rails@lists.rubyonrails.org >> Subject: Re: [Rails] Showing Images from a file store >> >> >> send_file ''/path/to.jpeg'', :type => ''image/jpeg'', :disposition => >> ''inline'' >> >> Silvy@funmail.com wrote: >>> Hi all. >>> I am wrting a small content management tool for my company and was >>> trying to display some images from our file store shown below. >>> <td> <img src="\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"/> >>> The app was displaying the image when it is under the \public\images > >>> directory. >>> Is there anything special we need to do to get a file from outside >>> the >>> root of the application? >>> >>> Any help appreciated. >>> >>> Thanks >>> Silvy Mathews >>> _______________________________________________ >>> Rails mailing list >>> Rails@lists.rubyonrails.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi John, That really worked. I did not knew that we could specify a controller name and the method name inside the view. Thanks a lot. Really appreciate that. Thanks Silvy On 4/13/06, John Bresnik <jbresnik@ibaset.com> wrote:> > > Here''s a [very] rough, but working example for a PDF.. > > Controller: > > class FileGrabberController < ApplicationController > @@path = ''your/path'' > def get_file > send_file @@path + ''a.pdf'', :type => ''application/pdf'' > end > end > > View: > > <a href="file_grabber/get_file">pdf</a> > > I know there''s an inline option as well, i.e. for a JPG > > :disposition => ''inline'' > > <img src="file_grabber/get_image"/> > > or something like that - hope that helps.. > > brez > > > Silvy@funmail.com wrote: > > Hi, > > Thanks a lot for the response. If you can post a working example, that > > would be great. > > Really appreciate it. > > Thanks > > Silvy Mathews > > > > -----Original Message----- > > From: rails-bounces@lists.rubyonrails.org > > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of > > endaxbrez@endax.com > > Sent: Wednesday, April 12, 2006 5:15 PM > > To: rails@lists.rubyonrails.org > > Subject: RE: [Rails] Showing Images from a file store > > > > Yea sorry my response was a little short - that function would go in the > > controller, i.e. > > > > class FileGrabberController < ApplicationController > > def grab_file > > send_file ''/path'', :type => ''image/jpeg'', [etc] > > end > > end > > > > then either call the controller directly using an image tag or use a > > helper.. > > let me know if that helps - I can post a working example when I get home > > tonight [on the laptop at home].. > > > > > > > > > > > > Quoting Silvy@funmail.com: > > > >> Hi John, > >> Thanks for the quick response. > >> I wanted to show the image along with other data from the controller. > >> How do I do that. Looks like I am not understanding it. > >> <td><%= column1 from the model%> > >> <td><%= column1 from the model%> > >> <td><%= column1 from the model%> > >> <td><%= send_file ''\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"'', > >> :type => ''image/jpeg'', > >> :disposition => ''inline''%> > >> > >> Would not work. Sorry for my ignorance. > >> > >> Thanks > >> Silvy Mathews > >> > >> > >> -----Original Message----- > >> From: rails-bounces@lists.rubyonrails.org > >> [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of John Bresnik > >> Sent: Wednesday, April 12, 2006 11:53 AM > >> To: rails@lists.rubyonrails.org > >> Subject: Re: [Rails] Showing Images from a file store > >> > >> > >> send_file ''/path/to.jpeg'', :type => ''image/jpeg'', :disposition => > >> ''inline'' > >> > >> Silvy@funmail.com wrote: > >>> Hi all. > >>> I am wrting a small content management tool for my company and was > >>> trying to display some images from our file store shown below. > >>> <td> <img src="\\xx.xx.xxx.xx\xx\xx\xxx\abc.gif"/> > >>> The app was displaying the image when it is under the \public\images > > > >>> directory. > >>> Is there anything special we need to do to get a file from outside > >>> the > >>> root of the application? > >>> > >>> Any help appreciated. > >>> > >>> Thanks > >>> Silvy Mathews > >>> _______________________________________________ > >>> Rails mailing list > >>> Rails@lists.rubyonrails.org > >>> http://lists.rubyonrails.org/mailman/listinfo/rails > >>> > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> _______________________________________________ > >> Rails mailing list > >> Rails@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060413/e1dcd686/attachment.html
> That really worked.good to hear..>I did not knew that we could specify a controller > name > and the method name inside the view.well what youre really specifying is a URL that is interpreted as that method on that controller, i.e. the rails convention for URL mapping. The browser then retrieves the img like a typical JPG. send_file returns a byte stream [i.e. no HTTP headers, etc] which is subsequently rendered.. It all pretty straightforward actually - it''s probably worth reading abt the HTTP 1.1 protocol if you found the previous few lines compelling.. -- Posted via http://www.ruby-forum.com/.