DamnBigMan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-25 22:26 UTC
File Upload Problems
I am obviously doing something wrong when implementing the rubyonrials
wiki code for uploading a file.
I don''t seem to be getting the actual file object included with the
form, as it complains about trying to call read on a string object.
How do I get the actual file that was uploaded?
Here is my code:
Controller
def auto
if request.post?
@sched = Schedule.new
@sched.automate(params[:schedule])
end
end
Model
def automate(schedule)
File.open("schedule_store/#{schedule[''filename'']}",
"w") { |f|
f.write(schedule[''filename''].read) }
end
View
<p>
<b>Schedule:</b>
<input type="file" name="schedule[filename]" />
</p>
--~--~---------~--~----~------------~-------~--~----~
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 have had great success with acts_as_attachment plugin. :ivor On 4/26/07, DamnBigMan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <DamnBigMan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I am obviously doing something wrong when implementing the rubyonrials > wiki code for uploading a file. > > I don''t seem to be getting the actual file object included with the > form, as it complains about trying to call read on a string object. > > How do I get the actual file that was uploaded? > > Here is my code: > > Controller > > def auto > if request.post? > @sched = Schedule.new > @sched.automate(params[:schedule]) > end > end > > > Model > > def automate(schedule) > File.open("schedule_store/#{schedule[''filename'']}", "w") { |f| > f.write(schedule[''filename''].read) } > end > > > View > > <p> > <b>Schedule:</b> > <input type="file" name="schedule[filename]" /> > </p> > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
DamnBigMan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-26 16:34 UTC
Re: File Upload Problems
Figured out how to get my file uploaded although I can''t access the
origional_filename now. This is starting to frustrate me. I don''t
really want or need all the extra stuff included in acts_as_attachment
and I have to interact with it via the commandline, RadRails hasn''t
fixed their server problem yet (been a month now) so I can''t update
plugins through Eclipse.
If anyone could help me get this working that would be fantastic.
Here is the new code which uploads the file but won''t let me get the
filename (I have to give it a generic name).
Model
def self.automate(schedule)
@file_name = "test"
schedule[:schedule_file].rewind
File.open("schedule_store/#{@file_name}", "w") { |f|
f.write(schedule[:schedule_file].read) }
end
Controller
def auto
if request.post?
@sched = Schedule.automate(params[:schedule])
end
end
View
<% form_for(:schedule, @schedule, :url => {:action =>
''auto''}, :html
=> {:multipart => true}) do |form| %>
<p>
<b>Schedule:</b>
<%= form.file_field :schedule_file %>
</p>
<%= submit_tag "Auto" %>
<% end %>
Thanks,
Glen
On Apr 26, 3:13 am, "Ivor Paul"
<ivorp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I have had great success with acts_as_attachment plugin.
>
> :ivor
>
> On 4/26/07, DamnBig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
<DamnBig...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> > I am obviously doing something wrong when implementing the rubyonrials
> > wiki code for uploading a file.
>
> > I don''t seem to be getting the actual file object included
with the
> > form, as it complains about trying to call read on a string object.
>
> > How do I get the actual file that was uploaded?
>
> > Here is my code:
>
> > Controller
>
> > def auto
> > if request.post?
> > @sched = Schedule.new
> > @sched.automate(params[:schedule])
> > end
> > end
>
> > Model
>
> > def automate(schedule)
> >
File.open("schedule_store/#{schedule[''filename'']}",
"w") { |f|
> > f.write(schedule[''filename''].read) }
> > end
>
> > View
>
> > <p>
> > <b>Schedule:</b>
> > <input type="file"
name="schedule[filename]" />
> > </p>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---