djburdick
djburdick

Reputation: 11940

rails: running a method on create only

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!

Upvotes: 0

Views: 500

Answers (1)

shingara
shingara

Reputation: 46914

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.

Upvotes: 1

Related Questions