jspooner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-19 05:42 UTC
attachment_fu - public_filename in Controller
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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...
jspooner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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: http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html#M001135 On Feb 19, 12:42 am, "jspoo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" <jspoo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---