hi I am trying to get the "Full path of a uploaded file" . In my view I am using file_field to upload a file. Below is my view code <table border="0" align="center"> <tr> <td> <label for="dump_file"> Select a CSV File : </label> </td> <td > <%= f.file_field :file -%> </td> </tr> <tr><td></td><td></td></tr> <tr> <td colspan=''2'' align="center"> <%= submit_tag ''Submit'' -%> </td> </tr> </table> In a controller class when I try params[:dump][:file].original_filename it gives me only the filename of file. I need to parse the uploaded file(.csv file) in my controller. Can you please let me know how to get the full path of a file -- 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 -~----------~----~----~----~------~----~------~--~---
you don''t need that to parse the csv file. something like this (in Model) will do: attr_accessor :invitations_csv_file def upload_invitations if invitations_csv_file && invitations_csv_file != "" then CSV::Reader.parse(invitations_csv_file.read) do |parsed| # do something here with the parsed content (fields in parsed[0], parsed[1]...) end end end In controller: @edition.invitations_csv_file = params[:file] @edition.upload_invitations --~--~---------~--~----~------------~-------~--~----~ 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 shailey, just to add to thorsten''s note: the uploaded file is passed as a UploadedStringIO to your controller. It''s not saved anywhere, so there isn''t a full path. You can save it yourself if you want, so it''s up to you to choose the path. Or like thorsten suggests directly parse it and save its contents in the database in any structure you like. dirk. On Sep 8, 10:41 am, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote:> you don''t need that to parse the csv file. > > something like this (in Model) will do: > > attr_accessor :invitations_csv_file > > def upload_invitations > if invitations_csv_file && invitations_csv_file != "" then > CSV::Reader.parse(invitations_csv_file.read) do |parsed| > # do something here with the parsed content (fields in > parsed[0], parsed[1]...) > end > end > end > > In controller: > > @edition.invitations_csv_file = params[:file] > @edition.upload_invitations--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---