Showing posts with label attachment_fu. Show all posts
Showing posts with label attachment_fu. Show all posts

Tuesday, October 21, 2008

RSpec, attachment_fu

I've been looking for a solution to force RSpec tests to override the attachment_fu storage setting. Since I use s3, it was very inefficient when I'd run my tests because the assets would be saved in s3. Not only does it cost money, but it was very slow.

After spamming #rubyonrails I finally got an answer from _martinS_. He told me to do something like this: http://pastie.org/296895 - and it worked! I hope this helps you guys.

Tuesday, September 9, 2008

attachment_fu, Rails 2.1 and before_thumbnail_saved

I was working on before_thumbnail_saved callback in Rails 2.1 and it seems it has changed! It didn't work with me anymore. At least my old code didn't.

Apparently, you only pass the thumbnail into the loop.

Read this blog post for details.

Friday, September 5, 2008

Rake: Update or create images generated by attachment_fu

Did you upload a bunch of images and find out that the new layout needs a new size of the photos, and you didn't specify this in the has_attachment line of your model?

This happened to me, and I wanted an easy to way update all images in the database. I didn't test this with millions of records or anything, but if you want to fix this up please leave a comment.

Notes:
  • To use, simply edit has_attachment line with the new thumbnail sizes you want.
  • IdeaImage is the model that I want to update
  • parentless is a named_scope that gets only the IdeaImages whose parent_id's are null.

namespace :images do
desc "Updates all the thumbnails of idea_images based on the thumbnails hash in the model"
task(:update_idea_images => :environment) do
IdeaImage.parentless.each do |i|
#destroy the thumbnails first
i.thumbnails.each { |thumbnail| thumbnail.destroy } if i.thumbnailable?
#then recreate the thumbnails
i.attachment_options[:thumbnails].each { |suffix, size| i.create_or_update_thumbnail(i.create_temp_file, suffix, *size) }
end
end
end

Saturday, March 22, 2008

GawingAttachable

Do you want to be able to attach files to something? I needed to do that today and I made a plugin called Gawing Attachable (translated: make_attachable). It allows you to add attachments to something you make attachable.

Yes, there are many things you can still do to this, but like they say: make something quick and fix it up later on.

Check out the README before installing.
script/plugin install http://lucidph.dreamhosters.com/gawing_attachable/trunk

Friday, February 8, 2008

Expected "model.rb" to define Model

I was getting this error:

ActionView::TemplateError (Expected /home/lucidph/public_html/rails/pbed/app/models/article_photo.rb to define ArticlePhoto) on line #5 of articles/gen_xml.xml.builder

A lot of people get this with ferret and some bug with it, but I didn't have ferret. The problem: I forgot to upload attachment_fu to the server!

Wednesday, October 3, 2007

You can't upload files via ajax alone!

Spent the morning figuring out something you can't do! I was trying to make an ajax file uploader but kept running into problems. I asked around #rubyonrails in freenode but got no answer so I did some searching... and found a thread of this person that tried to do the exact same thing.

Tuesday, September 25, 2007

Tutorial: attachment_fu: fixing the Windows error on size

It took me a while to find this, but I finally found my answer in a forum thread.