Hi there,
This is the site I looked at to get the same thing working on my site.
http://www.albert.bagasie.com/RailsTips/FileUpload
Cheers
Kevin Fullerton
On Wed, Jul 20, 2005 at 04:17:31PM -0700, Hunter Hillegas
wrote:> I am working on my first Rails app.
>
> I need to upload a file via an HTML form. The file will be stored in the
> file system and the URI to the file stored in the database.
>
> I''ve read through the instructions here:
> http://wiki.rubyonrails.com/rails/revision/HowtoUploadFiles
>
> They form the basis of what I''ve got so far.
>
> Right now, when I submit I actually don''t get any errors... But
the file
> doesn''t seem to be uploaded and the database doesn''t get
updated either...
> I''m probably making a simple mistake but perhaps y''all
can point me in the
> right direction?
>
> Some applicable code bits follow.
>
> Thx,
> Hunter
>
> View:
>
> <%= form_tag({:action => ''photo_form'', :id =>
@home_page_element},
> :multipart => true) %><!--[form:home_page_element]-->
> <!-- File -->
> <%= file_field(:home_page_element, ''issue_as_cover'')
%>
> <!-- Other Attribute - Short Quote -->
> <%= text_field ''home_page_element'',
''short_quote'', :class => "gen" %>
> <%= submit_tag "Save Changes", options = {:class =>
"del"} %>
> <!--[eoform:home_page_element]--><%= end_form_tag %>
>
> Controller:
>
> def photo_form #handle photo upload
> @home_page_element = HomePageElement.find(params[:id])
> @home_page_element.save(@params[:home_page_element])
>
> puts @params[:home_page_element] #want to see what I get - looks ok
>
> redirect_to :action => ''photo'', :id =>
@home_page_element
> end
>
> Model:
>
> def self.save(home_page_element)
>
>
File.open("#{RAILS_ROOT}/public/images/#{home_page_element[''issue_as_cover'']
> }", "wb") { |f|
f.write(home_page_element[''issue_as_cover''].read) }
>
> self.photo_uri =
home_page_element[''issue_as_cover''].original_filename
> self.short_quote = home_page_element[''short_quote'']
> end
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails