June 11th, 2007
ive read through some forums that it could be lack of memory or fcgi, since someone on my hosting site reported that they are not having the problem once they switched over to mongrel. other than that, not really sure what the problem is. it could be timing out from the resizing/uploading the three files i have set. oh well for now.
May 30th, 2007
the other day i came across a problem for one of my sites that is using attachment_fu and amazon’s s3 service.
Read the rest of this entry
March 26th, 2007
nothing to report here but maybe someone out there got a similar careless problem like me!. Basically I was following the directions at http://clarkware.com/cgi/blosxom/2007/02/24 and everything was working fine but I ran into a problem with the loading of the amazon_s3.yml file. I tried manually setting the variables in the lib directory but no avail. finally i decided to put all the information of passkey/bucket/secret key in all three sections of the yml file. well that did the trick. amazon s3 is awesome and with attachment_fu, everything is easy!
March 14th, 2007
this question seems to pop up in the rails forums at least twice a week. so i guess this may be a beneficial post to folks out there looking to simply add more than 1 file field in a form. remember, the grunt is new to ror so any improvements to this post, please drop me a message.
so far this is what i did.
follow techno weenie tutorial here for creating your model that will store the photos.
In our example, lets say you have a foodrecipe model and a food_photos model. you would do “script/generate attachment_model food_photos”
Next, add your foodrecipe_id to your migration file for your foodphotos.
Next, add your relationships to your model. Therefore,
foodrecipe has_many :foodphotos,
and
foodphotos model, belongs_to foodrecipe.
Next in the action that calls your form, instantiate as many files you would like to add. for example in the dvdcover example, you do @dvd_cover = DvdCover.new. so in our example you can do
@myrecipe = Foodrecipe.new
@myPhoto1 = Foodphoto.new
@myPhoto2 = Foodphoto.new
etc…
now in your form, you can add the file fields.
for example in the dvdcover example you would do this..
<% form_for :dvd_cover, :url => { :action => ‘create’ }, :html => { :multipart => true } do |f| -%>
<%= f.file_field :uploaded_data %>
<%= submit_tag :Create %>
<% end -%>
but now, you can do this. (i am sure there is a much better way but this is what i know so far)
<% form_for :myrecipe , :url => { :action => ‘create’ }, :html => { :multipart => true } do |f| -%>
...stuff for your recipe here
<%= file_field “myPhoto1” , “uploaded_data” %>
<%= file_field “myPhoto2” , “uploaded_data” %>
...etc.
<%= submit_tag :Create %>
<% end -%>
now in your create action, build how a has_many is built by doing the following
@foodrecipe = Foodrecipe.new(params[:myrecipe])
@foodrecipe.save
@foodrecipe.foodphoto.build[params[:myPhoto1]]
@foodrecipe.foodphoto.build[params[:myPhoto2]]
that should be able to save your multiple files. this is probably the bruteforce way, so if this can be made better, please drop me a message. thanks!
February 23rd, 2007
For this task, the grunt is currently using acts_as_attachment. Information about the plugin can be found here . Follow the directions carefully and you can easily add file upload option to your rails application. Al the files are stored in the public folder in its own id directory. Also whats cool about it is that acts_as_attachment also creates thumbnails of each photo you upload. So in your view you can have something like this…assume that artices has one articlephoto
<% for articles in @toparticles%>
<= article.title>%>
<%if article.articlephoto != nil %>
<= image_tag article.articlephoto.thumbnails0.public_filename>
<% end %>
easy aint it?