Topic: how to get filename in edit?

Hi,

I'm unable to find what i'm looking for in google.
I would like to have the current filename when i edit a page.

result like :
http://content.screencast.com/users/stephanebaribeau/folders/Default/media/69fc4b60-c5f2-4fd1-a9e0-57c1b139ffe0/getcurrentfile.png

The image are in a nested form.
i have 2 files attached. With file_field, i know i can't get filename in the textbox, but i want to show it at his right.

the create method are set like : @building.building_pdfs.build.

I have tryed something like : @building.building_pdfs in my _form html page. but i got an array, its normal i think but how to get id attached to this file_field?

My array are

[#<BuildingPdf id: 9, pdf_name: nil, created_at: "2011-08-05 13:39:09", updated_at: "2011-08-05 13:39:09", pdf_file_name: "Calendrier-annee-scolaire-2011-2012.pdf", pdf_content_type: "application/pdf", pdf_file_size: 1051417, pdf_updated_at: "2011-08-05 13:39:09", building_id: 2>, #<BuildingPdf id: 10, pdf_name: nil, created_at: "2011-08-05 13:39:09", updated_at: "2011-08-05 13:39:09", pdf_file_name: "Ch21Examples_ChangeCreditPolicy.pdf", pdf_content_type: "application/pdf", pdf_file_size: 39645, pdf_updated_at: "2011-08-05 13:39:09", building_id: 2>]

does rails have a way to get file_name attached to his file_field?

thanks.

Last edited by neimad (2011-08-05 12:01:37)

Re: how to get filename in edit?

original_filename

i.e.

params[:pfd].original_filename

assuming your file_field is named pdf.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: how to get filename in edit?

Thanks, i have tried, but not worked!
I got error this error message : undefined method `original_filename' for nil:NilClass

thanks!

Re: how to get filename in edit?

if you created a file_field in your form called 'pdf',  then in your controller (update,create) you should be able to do

params[:pdf].original_filename

the :pdf is arbitrary,  I don't know what you called your file_field attribute,  I used 'pdf' as an example

post the controller code where your trying to get at the file name of the uploaded file.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: how to get filename in edit?

Here is the simplest example I can think of:

<% form_for '/upload', :multipart=>true %>
    <% file_field_tag :pdf %>
<% end %>


in a controller.rb:

def upload
     filename = params[:pdf].original_filename
end

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: how to get filename in edit?

thanks for your help that works right  now.