This is probably me having an issue with the mvc way of living… .I’m
used to perl/php scripting…
I’ve got a photo blog I’m making… and in past iterations of this
website, I’d just name the photos after the id of the entry. For
instance:
/photos/id.jpg
/photos/id_thumb.jpg
However, I’m having trouble finding an easy way to do this with rails.
Everywhere I read either has an example of how to upload the file
directly into a database, or to use file_column. While file_column
looks nice and easy, it kind of bugs me that I’d have to create two
columns in my table to support the ability to upload a file… if I
have to do this, then I will, but I was curious if there is any easy way
to do this.
The only possibility I found was here:
http://wiki.rubyonrails.com/rails/pages/HowtoUploadFiles
However, there were a couple of things I wasn’t sure on:
- in the view:
What is [picture] a reference to? this isn’t being stored in the
database… is it just so we can access it with the person class?
- The use of file.open… I haven’t had much luck finding
documentation on all the options…
File.open(“pictures/#{person[‘name’]}/picture.jpg”, “w”) { |f|
f.write(person[‘picture’].read) }
I’d really appreciate any help or suggestions.
Thanks
-tyler