views:

50

answers:

1

I want to run a paperclip method on create only

has_attached_file :file

This method doesn't seem to accept the :on => :create that some other rails methods do.

I tried:

before_create
after_create

etc, but those didn't work.

I also did:

if :create

How can I test if the controller is using the create method from the model?

Thanks!

+1  A: 

When you use has_attached_file :file. There are 2 new callback and you can use it :

before_file_post_process
after_file_post_process

So you can use it and check if you object is in creation or not with new_record?

The before_create and after_create are allway present, but independent of your attachment.

shingara
I would like for has_attached_file to not even get called unless it's on create
bandhunt
You misunderstand what `has_attached_file` does. It's called only once, when the class file is loaded, and what it does is create a load of other methods and variables that allow the object to process attachments at various points in the object's lifespan. So, the next step is to work out and explain specifically what you only want to happen on create.
Gareth
right. I understand it's only called once, but I only want it to be called when the create method in the controller is called - not any other time the model is called. When a user updates just the text associated with a file it's still calling the file transfer stuff (I modified paperclip to use sftp)
bandhunt