# Attachment\_fu - public\_filename in Controller

**URL:** <https://www.ruby-forum.com/t/attachment-fu-public-filename-in-controller/129514>\
**Category:** Rails\
**Created:** [February 19, 2008, 6:42am UTC](https://www.ruby-forum.com/t/attachment-fu-public-filename-in-controller/129514 "2008-02-19T06:42:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 19, 2008, 6:42am UTC](https://www.ruby-forum.com/t/attachment-fu-public-filename-in-controller/129514/1 "2008-02-19T06:42:44Z")

</div>

My brain hurts, please help.

I’ve beaten my head against the wall for hours trying to figure out  
why I cant get the public\_filename  
is only accessible from the views?

I need to get the full file path in the controller so I can render a  
JSON object for Flash to pick up.

products = Product.find(:all,{ :include =\>  
[:seasons, :collections, :types], :conditions =\> [“sex=? AND  
seasons.id=(?)”,params[:sex] , params[:season] ] })  
render :text =\> products.to\_json

Thanks for you help

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 19, 2008, 7:17am UTC](https://www.ruby-forum.com/t/attachment-fu-public-filename-in-controller/129514/2 "2008-02-19T07:17:07Z")

</div>

hi …  
i was having a project in front where i was uploading videos. i have  
used following definition for over witting the full\_filename as  
def full\_filename  
user\_id = self.user\_id  
videopath = attachment\_options[:path\_prefix].to\_s + user\_id.to\_s +  
VIDEO\_DIR  
file\_system\_path = videopath  
path = File.join(RAILS\_ROOT, file\_system\_path , filename)

end  
i m storing my videos in public/swf/videos/user\_id/video\_id path  
so i have stored a constant  
DOCUMENT\_DIR = ‘public/swf/uploads/’  
VIDEO\_DIR = ‘/videos/’  
in the environment.rb… this way i can access the files…

removed\_email\_address@domain.invalid wrote:

> My brain hurts, please help.
> 
> I’ve beaten my head against the wall for hours trying to figure out  
> why I cant get the public\_filename  
> is only accessible from the views?
> 
> I need to get the full file path in the controller so I can render a  
> JSON object for Flash to pick up.
> 
> products = Product.find(:all,{ :include =\>  
> [:seasons, :collections, :types], :conditions =\> [“sex=? AND  
> seasons.id=(?)”,params[:sex] , params[:season] ] })  
> render :text =\> products.to\_json
> 
> Thanks for you help

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 19, 2008, 4:58pm UTC](https://www.ruby-forum.com/t/attachment-fu-public-filename-in-controller/129514/3 "2008-02-19T16:58:27Z")

</div>

I believe that public\_filename is an instance method, not a stored  
attribute, so you’ll need to give to\_json some help. to\_json, like  
to\_xml, supports parameters that help you make your rendering more  
specific. In this case specifically I think you need to look into  
making use of the :include (specify the associations to be part of the  
json), and :methods (specify instance methods on the object to be  
included).

Check here for more:

> **[ActiveRecord::Serialization](https://api.rubyonrails.org/classes/ActiveRecord/Serialization.html#M001135)**
>
> Active Record Serialization.
