On Mar 13, 2008, at 9:59 AM, pharrukh. wrote:
>
> Hello all,
>
> i am trying to upload a file through Ruby on Rails since last week.
> Could anyone please guide me regarding a simple upload process. Or
> guide me to a ''working'' example/tutorial of uploading.
>
> Waiting curiously for a respons,
>
> Regards,
>
> pharrukh.
The important bit that''s easy to forget is the :multipart=>true
==> in your view new.rhtml <=
<% form_for(:something, @something, :url => somethings_path, :html =>
{ :multipart => true }) do |f| -%>
<p> <label for="something_data">Something
File</label>:<br />
<%= f.file_field ''data'' %> </p>
<%= submit_tag "Submit", :name => nil %>
<% end %>
==> in the SomethingController#create action <=
data = params[:something].delete(''data'') #
HashWithIndifferentAccess still needs the actual key type to .delete
params[:dump] = "data=#{data.inspect}"#;
filename=#{data.original_filename}; content_type=#{data.content_type}"
if data.blank?
flash[:error] = "No something file selected for upload"
redirect_to :action => ''new'' and return
end
content = data.read
if content.blank?
flash[:error] = "Selected something file was empty"
redirect_to :action => ''new'' and return
end
That should get you going.
-Rob
Rob Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---