Forum: Ruby on Rails Creating records with file upload in migration

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
30d65340ad6d7fa42aeb8ef7821d05b3?d=identicon&s=25 Dan Smith (jitsudan)
on 2009-01-27 20:26
Hi,
I have a migration which creates several records along with the table.
eg
Forum.create :title => "General Discussion", :description => "General
Chit-Chat"

But I'd like to create a record which accepts an uploaded file, such as
a jpeg.  Is it possible to automate this using the above technique?

Thanks
Ed437e52d8d6720308720e7e678f3e6d?d=identicon&s=25 Patrick Doyle (Guest)
on 2009-01-27 20:38
(Received via mailing list)
On Tue, Jan 27, 2009 at 2:26 PM, Dan Smith
<rails-mailing-list@andreas-s.net
> wrote:

> Thanks
>
How does your Forum model currently upload a file?  Do you use an
after_save
callback to write the file into your file storage directory?  Could you
modify your callback to accept a filename from somewhere else in the
filesystem and have it simply copy that file to your file storage
directory?

--wpd
47c3af2d56d44eb1d08a601c837a1262?d=identicon&s=25 alberto (Guest)
on 2009-01-28 02:53
(Received via mailing list)
> I have a migration which creates several records along with the table.
> eg
> Forum.create :title => "General Discussion", :description => "General
> Chit-Chat"

I am not sure you want to combine migrations with record creation. It
is probably best for you to handle this via a load script or a rake
task.

As to the file upload, if you are using a plugin like attachment_fu,
then you are all set. Take a look at the plugin tests directory to see
how those simulate the upload of files and create the uploaded files
either in the db or in the path you specified in your models.
This topic is locked and can not be replied to.