# Dynamic path to store images using attachment\_fu

**URL:** <https://www.ruby-forum.com/t/dynamic-path-to-store-images-using-attachment-fu/173284>\
**Category:** Rails\
**Created:** [August 6, 2009, 8:55am UTC](https://www.ruby-forum.com/t/dynamic-path-to-store-images-using-attachment-fu/173284 "2009-08-06T08:55:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [August 6, 2009, 8:55am UTC](https://www.ruby-forum.com/t/dynamic-path-to-store-images-using-attachment-fu/173284/1 "2009-08-06T08:55:56Z")

</div>

Hello friends,

I need to store the images of user into there own directory for e.g  
“public/uploads/user\_(user\_id)”  
So I am declaring it inside the model.

has\_attachment :path\_prefix =\> ‘public/uploads/user\_#{current\_user}’

As current user is not accessible from model. So in this case how can i  
save  
the images into the user directory?

Please help me with this situation.

Regards  
Abhi

---

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://www.ruby-forum.com/u/Abhishek_shukla)\
**Post date:** [August 6, 2009, 9:38am UTC](https://www.ruby-forum.com/t/dynamic-path-to-store-images-using-attachment-fu/173284/2 "2009-08-06T09:38:52Z")

</div>

Abhishek shukla wrote:

> Hello friends,
> 
> I need to store the images of user into there own directory for e.g  
> “public/uploads/user\_(user\_id)”  
> So I am declaring it inside the model.
> 
> has\_attachment :path\_prefix =\> ‘public/uploads/user\_#{current\_user}’
> 
> As current user is not accessible from model. So in this case how can i  
> save  
> the images into the user directory?
> 
> Please help me with this situation.
> 
> Regards  
> Abhi

If user got any unique ID and if you are using login,then you can access  
user id from session…or you can create a session for each user and  
access it from there…  
Thank you…
