# Serving files from public

**URL:** <https://www.ruby-forum.com/t/serving-files-from-public/130089>\
**Category:** Rails\
**Created:** [February 25, 2008, 10:26am UTC](https://www.ruby-forum.com/t/serving-files-from-public/130089 "2008-02-25T10:26:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![addywaddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@addywaddy](https://www.ruby-forum.com/u/addywaddy)\
**Post date:** [February 25, 2008, 10:26am UTC](https://www.ruby-forum.com/t/serving-files-from-public/130089/1 "2008-02-25T10:26:30Z")

</div>

Hi,

I am building a rails app which supports accounts based on subdomain  
names. I want to serve files in public with respect to the subdomain  
name. For example:

url: [foo.myapp.com](http://foo.myapp.com)  
 ![]() should deliver public/foo/images/bar.jpg.

Is there any way to do this in rails? Or should I use the  
Mongrel::HttpHandler and response.send\_data?

Regards

Adam

---

<div class="post-metadata">

**Author:** ![addywaddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@addywaddy](https://www.ruby-forum.com/u/addywaddy)\
**Post date:** [February 25, 2008, 10:54am UTC](https://www.ruby-forum.com/t/serving-files-from-public/130089/2 "2008-02-25T10:54:49Z")

</div>

On 25 Feb 2008, at 10:26, Adam G. wrote:

> I am building a rails app which supports accounts based on subdomain  
> names. I want to serve files in public with respect to the subdomain  
> name. For example:
> 
> url: [foo.myapp.com](http://foo.myapp.com)  
> ![]() should deliver public/foo/images/bar.jpg.
> 
> Is there any way to do this in rails? Or should I use the  
> Mongrel::HttpHandler and response.send\_data?

Using the account\_location plugin, something like this should work:

image\_tag(“/#{account\_subdomain}/images/#{picture\_name}”)

Although I would advise you to create a separate folder in public to  
store all your user images, otherwise your public folder will become  
a huge collection of folders pertaining to rails and your customers.  
Hard to keep track of them and back them up efficiently and you’ll  
have serious problems if you deploy via capistrano if you use your  
method.  
Something like /public/user\_images/subdomain/image.jpg would be more  
appropriate.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![addywaddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@addywaddy](https://www.ruby-forum.com/u/addywaddy)\
**Post date:** [February 25, 2008, 11:07am UTC](https://www.ruby-forum.com/t/serving-files-from-public/130089/3 "2008-02-25T11:07:29Z")

</div>

Thanks for the reply Peter. I should have been clearer in my post: the  
idea is that users will be able to add content via Textile, meaning that  
Rails helpers will not be used for generating image or link paths.

---

<div class="post-metadata">

**Author:** ![addywaddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@addywaddy](https://www.ruby-forum.com/u/addywaddy)\
**Post date:** [February 25, 2008, 11:30am UTC](https://www.ruby-forum.com/t/serving-files-from-public/130089/4 "2008-02-25T11:30:57Z")

</div>

On 25 Feb 2008, at 11:07, Adam G. wrote:

> Thanks for the reply Peter. I should have been clearer in my post: the  
> idea is that users will be able to add content via Textile, meaning  
> that  
> Rails helpers will not be used for generating image or link paths.

Then how are you going to solve your problem of displaying images?

I’ve done something quite similar to what you have done, and this is  
my setup:

- Allow user to upload a collection of images (uses attachment\_fu),  
I’ve added the ability to shove them into albums and add some  
searchable tags to it
- Below my textarea (using Textile) they can browse through their  
images, select one and then click the “Insert” button. This could  
insert the correct the !image\_url! text into the textarea. I’ve done  
it a bit differently and have added my own tag parsing method (I  
don’t remember it too well, it’s an old project), something like  
&my\_image.jpg& so that the user doesn’t even see this is translated  
to /user\_images/subdomain/my\_image.jpg when saving the record.

And my comment on having to be able to easily symlink the folder  
containing the user images when deploying via capistrano still stands.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![addywaddy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ea5d25/32.png) [@addywaddy](https://www.ruby-forum.com/u/addywaddy)\
**Post date:** [February 25, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/serving-files-from-public/130089/5 "2008-02-25T12:40:07Z")

</div>

if you need moreour control, set up mod\_xsendfile and keep images  
outside of public  
there should be plugin, to make it even easier

On 25 ÆÅ×, 11:26, Adam G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
